Picaxe Dimmer |
|
To gain access to revision questions, please sign up and log in.
Note the improvised switches. Just press the brown and black wires down to make the pull-up connection to the + supply line..
; ================================== ; ===== INITIALISE THE PROGRAM ===== ; ================================== setfreq em16 ; External-clock Megahertz 16 ; ===== Rename b1, b2 and b3 to make the program easier to read ===== symbol pulse_high = b1 symbol pulse_low = b2 symbol portc_data = b3 ; ===== Start the program with about 50:50 mark space ratio pulse_high = 128 ; 128 / 4 milliseconds pulse_low = 255 - pulse_high ; (255 - 128) / 4 milliseconds ; ================================= ; ===== THE MAIN PROGRAM LOOP ===== ; ================================= start: ; ===== PULSE WIDTH MODULATION ============= high 0 ; Turn the motor on pause pulse_high ; Short time delay low 0 ; Turn the motor off pause pulse_low ; Short time delay ; ========================================== portc_data = pins ; Poll the speed control switches ; ===== Speed the motor up if this switch is pressed ================== if portc_data = 1 then ; Test the switch on C.0 inc pulse_high ; If it's pressed, increase the pulse_high time if pulse_high = 0 then; Prevent pulse_high going above 255 pulse_high = 255 ; Since 255 + 1 = 0, fix that problem end if pulse_low = 255 - pulse_high ; Calculate pulse_low end if ; ===================================================================== ; ===== Slow the motor down if this switch is pressed ================= if portc_data = 2 then ; Test the switch on C.1 dec pulse_high ; If it's pressed, decrease the pulse_high time if pulse_high = 255 then; Prevent pulse_high going below 0 pulse_high = 0 ; Since 0 - 1 = 255, fix that problem end if pulse_low = 255 - pulse_high ; Calculate pulse_low end if ; ===================================================================== jmp start ; Repeat the whole program loop ; =====================================================================
reviseOmatic V3 Contacts, ©, Cookies, Data Protection and Disclaimers Hosted at linode.com, London