Easy Bluetooth and Propeller
raleigh747
Posts: 13
I've been asked to post this code to see if we can figure out what is goign on.
Essentially, when ever pin 0 is grounded, the variables will display a value of 50. If any pins higher than pin 0 are grounded, the highest pin will be assigned an integer and the value calculated (if pin 9 is the heighest, it will report a value of 140). However, if the program looks at more than 8 pins at once (sensors_start = 0 and sensors_end > 7, it does not report the correct values. With sensors_end set to 8, this program is returning a value of 130 but pin 0 is the only pin that is grounded.
CON _clkmode = xtal1 + pll16x 'Feedback and PLL multiplier _xinfreq = 5_000_000 'External oscillator = 5 MHz sensors_start = 0 'Define lowest whisker port sensors_end = 8 'Define highest whisker port OBJ pst:"Parallax Serial Terminal" 'Start Terminal for visual output Debug:"FullDuplexSerial" VAR long a long b long c long d long e long f long g long h long i long j long k long l long m long n long o long p long q long r long s long t PUB WhiskerTest pst.start(9600) repeat until a#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times a#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(a) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded a:= 0 'Variable = 0 if a#>0 'See if previous variable was detected waitcnt(clkfreq/5+cnt) repeat until b#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times b#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(b) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded b:= 0 'Variable = 0 if b#>0 'See if previous variable was detected repeat until c#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times c#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(c) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded c:= 0 'Variable = 0 if c#>0 'See if previous variable was detected repeat until d#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times d#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(d) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded d:= 0 'Variable = 0 if d#>0 'See if previous variable was detected repeat until e#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times e#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(e) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded e:= 0 'Variable = 0 if e#>0 'See if previous variable was detected repeat until f#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times f#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(f) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded f:= 0 'Variable = 0 if f#>0 'See if previous variable was detected repeat until g#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times g#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(g) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded g:= 0 'Variable = 0 if g#>0 'See if previous variable was detected repeat until h#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times h#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(h) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded h:= 0 'Variable = 0 if h#>0 'See if previous variable was detected repeat until i#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times i#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(i) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded i:= 0 'Variable = 0 if i#>0 'See if previous variable was detected repeat until j#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times j#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(j) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded j:= 0 'Variable = 0 if j#>0 'See if previous variable was detected repeat until k#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times k#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(k) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded k:= 0 'Variable = 0 if k#>0 'See if previous variable was detected repeat until l#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times l#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(l) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded l:= 0 'Variable = 0 if l#>0 'See if previous variable was detected repeat until m#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times m#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(m) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded m:= 0 'Variable = 0 if m#>0 'See if previous variable was detected repeat until n#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times n#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(n) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded n:= 0 'Variable = 0 if n#>0 'See if previous variable was detected repeat until o#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times o#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(o) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded o:= 0 'Variable = 0 if o#>0 'See if previous variable was detected repeat until p#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times p#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(p) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded p:= 0 'Variable = 0 if p#>0 'See if previous variable was detected repeat until q#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times q#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(q) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded q:= 0 'Variable = 0 if q#>0 'See if previous variable was detected repeat until r#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times r#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(r) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded r:= 0 'Variable = 0 if r#>0 'See if previous variable was detected repeat until s#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times s#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(s) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded s:= 0 'Variable = 0 if s#>0 'See if previous variable was detected repeat until t#>=0 'Repeat code segement until variable has a value > 0 if ina[noparse][[/noparse]sensors_start] == 0 'If pin[noparse][[/noparse]sensors_start] is grounded (= 0) repeat 10_000 'Repeat whisker check 10,000 times t#>= (>|(ina[noparse][[/noparse]sensors_end..sensors_start]^$ff)*10+40) 'Assign lowest pin a value of 1 and the highest pin 20 'Multiple pin value by 10 and add 40 for height 'Record maximum value of 10,000 trials as variable pst.dec(t) 'Dsiplay variable pst.newline 'Start a new line in display else 'If pin[noparse][[/noparse]sensors_start] is not grounded t:= 0 'Variable = 0
Essentially, when ever pin 0 is grounded, the variables will display a value of 50. If any pins higher than pin 0 are grounded, the highest pin will be assigned an integer and the value calculated (if pin 9 is the heighest, it will report a value of 140). However, if the program looks at more than 8 pins at once (sensors_start = 0 and sensors_end > 7, it does not report the correct values. With sensors_end set to 8, this program is returning a value of 130 but pin 0 is the only pin that is grounded.
Comments
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Parallax Tech Support·
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Parallax Tech Support·
Seems to work. Once I have the whisker assembly, I'll know for sure but preliminary testing shows promise.