My SPIN logic is misbehaving
garyg
Posts: 420
Hi
I'M attempting to get my LCD display to show two different motor speeds.
When I press the P7 touch button, the MOTOR 2 speed should be reduced by 8.
This fairly works.
MOTOR1 should be displaying a value of 1111 on the LCD display, but it displays -1.
The PUB speed LCD should only update if a the button is pressed but the loop continues all the way always.
Any help with resolving this situation would help a lot
Thanks
.
I'M attempting to get my LCD display to show two different motor speeds.
When I press the P7 touch button, the MOTOR 2 speed should be reduced by 8.
This fairly works.
MOTOR1 should be displaying a value of 1111 on the LCD display, but it displays -1.
The PUB speed LCD should only update if a the button is pressed but the loop continues all the way always.
Any help with resolving this situation would help a lot
Thanks
.
OBJ LCD : "FullDuplexSerial.spin" Buttons : "Touch Buttons" CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 TxPin = 8 'TXPIN IS PIN #8 ON THE QUICKSTART BOARD. VAR LONG STACK[20] long sp3 long sp1 long sp2 long flag1 PUB Main sp1 := 1111 sp2 := 9999 sp3 := 1111 flag1 := 0 Buttons.start(_xinfreq / 6) ' Launch the touch buttons driver sampling 100 times a second dira[23..16]~~ ' Set the LEDs as outputs LCD.start(TxPin, TxPin, %1000, 9_600) WaitCnt(ClkFreq / 100 + Cnt) ' Pause to initialize LCD.tx(12) ' Clear LCD.tx(17) ' Turn on backlight LCD.str(String("Motor1")) ' First line LCD.tx(13) ' Line feed LCD.str(String("Motor2")) ' Second line LCD.tx(212) ' Set quarter note LCD.tx(220) ' A tone WaitCnt(ClkFreq * 3 + Cnt) ' Wait 3 seconds LCD.tx(18) ' Turn off backlight speed 'speed calls the Speed object to run PUB Speed repeat outa[23..16] := Buttons.State flag1 :=outa[23] if flag1 ==1 sp2:= sp2-8 flag1:=0 if sp3<>= sp2 'Only update the LCD if the speed number has changed. LCD.TX(136) 'Move cursor to line 0, position 8 LCD.Dec(sp3) 'Print Motor1 speed to LCD LCD.TX(156) 'Move cursor to line1, position 8 LCD.Dec(sp2) 'Print Motor2 speed to LCD LCD.tx(17) ' Turn on backlight WaitCnt(ClkFreq * 1 + Cnt) ' Wait 1 second ' sp3:= sp2+0 ' sets sp3 equal to current speed number sp2 LCD.tx(212) ' Set quarter note LCD.tx(220) ' A tone This tells me if this part of the loop was executed. WaitCnt(ClkFreq * 3 + Cnt) ' Wait 3 seconds
Comments
For code display use [noparse] [/noparse].
Your suggestions worked out very good.
The loop only runs when the pushbutton changes, otherwise it's is skipped.
I was able to add the ' sp3:= sp2+0 ' sets sp3 equal to current speed number sp2
Is updating the sp3 value in the above manner the best way to do that?
It appears to work, but it would seem to me like sp3:=sp2 should also work but it did not seem to work.
When I 1st power up the quickstart and LCD display, my default sp2 and sp3 settings are displayed.
After the 1st button press, the Motor1 and Motor2 displayed numbers are always 8 different.
For this particular application, it really does not matter.
I was using the default settings of sp2 and sp3 as a start.
The end result was exactly what I was looking for.
I'll be using this strategy to control the speed of HB25 motor controllers with a Parallax Keyfob remote.
Thanks
You made my day.