WhiteSpace
Well-known member
Following on from this post https://picaxeforum.co.uk/threads/bar-graph-display-on-ssd1306-oled.31765/ in which I described getting the OLED display to show the left and right motor control levels as bar graphs, I've now added IROUT to the first board (28x2) and set up a second breadboard with a second Picaxe (a 20M2 this time) to test for the motor remote control. I'm using a Vishay TSAL6200 IR LED and a TSOP4838. The IR LED has a red LED running off the same transistor so that I can see what's happening. The receiver drives a red (left) and green (right) LED for the same reason - in the final version there will be 2 motors instead of the LEDs. Turning the pots on the transmitter changes the speed of flashing of the receiver indicator LEDs. The LEDs on the transmitter and receiver seem to flash at the same speed. I'm just wondering whether there are any better ways of doing this or code shortcuts - the OLED now seems to catch up rather more slowly with the pot position.
The transmitter code looks like this:
The figures for the two pots are sent by the same IR LED, because I assume that i can't have two LEDs transmitting at the same time. So to differentiate between L and R I add 52 to the figure obtained from the R pot reading, after dividing by 5. Manual 2 at page 130 recommends sending the signal 10 times at 45ms apart. Presumably that slows things down quite significantly. Is it necessary? Are there any quicker solutions - can the 45ms be reduced at all?
At the receiving end, the code looks like this:
I would welcome any improvements! Thanks very much
The transmitter code looks like this:
Rich (BB code):
RightControl:
readadc B.4, b15; this uses a pot to give analogue control
let b4 = b15/5
Rich (BB code):
let b5 = b4 + 52 ; adds 52, to give a new figure for the b4 stored RightPot reading of between 52 and 103
; Left 0-20, 21-30, 31-51; Right 52-72, 73-82, 83-103
Transmit:
for b8 = 1 to 10
irout IRLed,1,b3 ; sends the LeftPot figure via infrared led
pause 45
next b8
for b8 = 1 to 10
irout IRLed,1,b5 ; sends the RightPot figure via infrared led
pause 45
next b8
goto LeftControl; back to check for the next motor signal
At the receiving end, the code looks like this:
Rich (BB code):
;picaxe 20M2
setfreq m8
main: ; Reminder - signals from IRIN are: Left 0-20, 21-30, 31-51; Right 52-72, 73-82, 83-103
SYMBOL RedLeftLED = B.5
SYMBOL GreenRightLED = B.6
CheckLEDs: ;flashes left and right LEDS 3 times to show that they are working
For b1 = 1 to 3
High RedLeftLED
pause 500
Low RedLeftLED
pause 500
Next b1
For b1 = 1 to 3
High GreenRightLED
pause 500
Low GreenRightLED
pause 500
next b1
FlashLEDs:
irin C.3,b0 ;reads the figure (0 to 127) from TSOP4838 and puts it in b0
if b0 >= 0 and b0 < 52 then let b5 = 102/b0 ; the range 0-51 is the left motor. Dividing 102 by b0 gives a simple indiactor that the speed control is carrying through to this board - if b0 is 1 (full rev), the LED will flash every 102ms. If b0 is 51, LED will flash every 2ms
elseif b0 >= 52 and b0 < 103 then let b6 = 204/b0; the range 52-102 is the right motor. As above
endif
For b1 = 1 to 5
High RedLeftLED
pause b5
Low RedLeftLED
High GreenRightLED
pause b6
Low GreenRightLED
Next b1
Goto FlashLEDs
End