' ' pwm.bs2 ' Drive the motor at a varying speed depending on the pot input ' Display the speed setting on the LCD ' ' Assumes: ' pin5: Bump button 1 (active high) ' pin6: RC input for pot ' pin7: PWM output to TIP41 base ' pin8: Serial output to serin of LCD ' pin9: Set input to latching relay ' pin10: Reset input to latching relay ' '''''''''''''''''' Useful LCD constants '''''''''''''''''''' LCDPREFIX con 254 LCDCLS con 1 LCDHOME con 2 LCDBLANK con 8 LCDSCRLLEFT con 24 LCDSCRLRT con 28 LCDCR con 192 N24N con 16780 '''''''''''''''''' Current PIN assignments ''''''''''''''''' LCD con 8 ' LCD serial output MOTOR con 7 ' Motor driver line POT con 6 ' RC pot input SET con 9 ' SET input to latching relay RST con 10 ' RST input to latching relay BUMP con 15 ' Bump button (active high) '''''''''''''''''' Local Variables ''''''''''''''''''''''''' result var word ' for RC timing wrk var byte ' button workspace direction var bit ' direction of travel ' 0 = forward, 1 = backward '''''''''''''''''' Initialise lines and vars ''''''''''''''' output LCD ' set the LCD pin to output output Motor ' set the PWM pin to output serout LCD,N24N,[LCDPREFIX, LCDCLS] ' clear the LCD low Motor ' turn off the motor direction = 0 ' start out going forward wrk = 0 ' clear button workspace ''''''''''''''''''''''''' Main Loop ''''''''''''''''''''''' loop: ' do an RC timing charge on a capacitor on pin Pot ' from this value, we deduce the motor speed control high POT ' charge the capacitor pause 1 ' wait for it to charge rctime POT,1,result ' do the RC timing result = result // 255 ' scale result to 0-255 range ' display the result on the LCD ' This can be commented out for final version serout LCD, N24N, [dec ? result] ' display the result serout LCD, N24N, [" "] ' display some blanking text serout LCD, N24N, [LCDPREFIX, LCDCR] gosub PrintDirection serout LCD,N24N, [LCDPREFIX, LCDHOME] ' home the cursor ' Pulse the Motor pin to drive the transistor pwm Motor, result, 100 ' Has anyone pressed the bump button button BUMP, 1, 255, 250, wrk, 0, noPress ' change button state direction = direction ^ 1 noPress: goto loop ' Assumes direction is stored in variable named direction ' Prints string on LCD with NO trailing characters PrintDirection: ' display the direction string if direction = 0 then Print_Forward serout LCD, N24N, ["Reverse"] return Print_Forward: serout LCD, N24N, ["Forward"] return