include 16f628_4 include jpic include jlib include jpwm3 --custom pwm library include jdelay include jrtl -- jrtl = operators -- tick MCLR off when programming!!!! var byte time = 1 var byte R = 255 var byte G = 1 var byte B = 1 var bit pause = false option = option & 0x7f disable_a_d_functions pin_a0_direction = output pin_a6_direction = input -- controls pause pin_a2_direction = output pin_a3_direction = output pin_a4_direction = output pin_a5_direction = output pin_a1_direction = input -- controls transistion pin_a7_direction = input -- controls speed pin_b0_direction = output pin_b1_direction = output pin_b2_direction = output pin_b3_direction = output pin_b4_direction = output pin_b5_direction = output pin_b6_direction = output pin_b7_direction = output -- procedures procedure speed is --controls speed if pin_a7 == high then time = 30 else time = 1 end if end procedure procedure flash is -- program to abruptly switch to another color var byte RR = 255 var byte GG = 1 var byte BB = 1 For 254 loop speed if pin_a1 == low then return end if PWM_OUT(RR,GG,BB, time) end loop while pin_a6 == high loop PWM_OUT(RR,GG,BB, time) end loop GG = 255 For 254 loop speed if pin_a1 == low then return end if PWM_OUT(RR,GG,BB, time) end loop while pin_a6 == high loop PWM_OUT(RR,GG,BB, time) end loop RR = 1 For 254 loop speed if pin_a1 == low then return end if PWM_OUT(RR,GG,BB, time) end loop while pin_a6 == high loop PWM_OUT(RR,GG,BB, time) end loop BB = 255 For 254 loop speed if pin_a1 == low then return end if PWM_OUT(RR,GG,BB, time) end loop while pin_a6 == high loop PWM_OUT(RR,GG,BB, time) end loop GG = 1 For 254 loop speed if pin_a1 == low then return end if PWM_OUT(RR,GG,BB, time) end loop while pin_a6 == high loop PWM_OUT(RR,GG,BB, time) end loop RR = 255 For 254 loop speed if pin_a1 == low then return end if PWM_OUT(RR,GG,BB, time) end loop while pin_a6 == high loop PWM_OUT(RR,GG,BB, time) end loop BB = 1 end procedure -- main loop forever loop For 254 loop -- (255,1,1) speed PWM_OUT(R,G,B, time) G = G + 1 if pin_a1 == high then flash end if while pin_a6 == high loop PWM_OUT(R,G,B, time) end loop end loop -- (255,255,1) For 254 loop -- (255,255,1) speed PWM_OUT(R,G,B, time) R = R - 1 if pin_a1 == high then flash end if while pin_a6 == high loop PWM_OUT(R,G,B, time) end loop end loop -- (1,255,1) For 254 loop -- (1,255,1) speed PWM_OUT(R,G,B, time) B = B + 1 if pin_a1 == high then flash end if while pin_a6 == high loop PWM_OUT(R,G,B, time) end loop end loop -- (1,255,255) For 254 loop -- (1,255,255) speed PWM_OUT(R,G,B, time) G = G - 1 if pin_a1 == high then flash end if while pin_a6 == high loop PWM_OUT(R,G,B, time) end loop end loop -- (1,1,255) For 254 loop -- (1,1,255) speed PWM_OUT(R,G,B, time) R = R + 1 if pin_a1 == high then flash end if while pin_a6 == high loop PWM_OUT(R,G,B, time) end loop end loop -- (255,1,255) For 254 loop -- (255,1,255) speed PWM_OUT(R,G,B, time) B = B - 1 if pin_a1 == high then flash end if while pin_a6 == high loop PWM_OUT(R,G,B, time) end loop end loop -- (255,1,1) end loop