-- based on librarys written by Stef Mientki -- RBG.jal -- Chester Lowrey 2003 -- program to controll 3 different color LEDs connected to port b 0,1,2 -- HSB (Hue, Saturation, Brightness) color controll is possible !! -- -- -- INPUT is via one 24 detent rotary encoder and one momentary contact pusbutton -- OUTPUT is 3 N channel mosfets driving the LEDs -- -------------------------------------------------------------------- -- -------------------------------------------------------------------- pragma target chip 16F628 pragma target clock 20_000_000 pragma target osc hs pragma target watchdog off pragma target powerup off pragma target protection off -- HS, -BOD, -CP pragma target fuses 0x3F22 -- pic 16F62x -- RA2 / AN2 / Vref 1 === 18 RA1 / AN1 -- RA3 / AN3 / CMP1 2 === 17 RA0 / AN0 -- RA4 / TOCK1 / CMP2 3 === 16 RA7 / OSC1 / CLKIN -- RA5 / -MCLR / THV 4 === 15 RA6 / OSC2 / CLKOUT -- Vss 5 === 14 VDD -- RB0 / INT 6 === 13 RB7 / T1OSI -- RB1 / RX / DT 7 === 12 RB6 / T1OSO / T1CK1 -- RB2 / TX / CK 8 === 11 RB5 -- RB3 / CCP1 9 === 10 RB4 / PGM -- -- REMARK RA4 has no pullup FET !! include jpic628 cmcon = 7 disable_comp pin_a0_direction = output -- Sound Pin pin_a1_direction = output -- current controll pin_a2_direction = output -- blank pin pin_a3_direction = output -- blank pin -- I specifically used pin A4 as the voltage controll because it doesnt have a pullup fet -- meaning that when it is set high the output just floats... -- in this case at the middle of a resistor network that sets the output voltage of the DC-DC pin_a4_direction = output -- voltage controll -- b 0 - 2 are for the PWM LEDs, declared further on pin_b3_direction = output -- blank pin pin_b4_direction = input -- momentary contact switch -- active low pin_b5_direction = output -- shutdown pin pin_b6_direction = input -- rotary encoder input pins pin_b7_direction = input -- second rotary bit var bit sound_pin is pin_a0 var bit current_controll is pin_a1 -- current limit, low = .5A high = 1A var bit voltage_controll is pin_a4 -- voltage controll, low = 5v, high = 4v var volatile bit mom_switch is pin_b4 -- momentary contact switch -- active low var bit shutdown_pin is pin_b5 -- shutdown var volatile bit encoder_A is pin_b6 -- rotary encoder input pins var volatile bit encoder_B is pin_b7 voltage_controll = on sound_pin = off -- -----------------------powerup sequence ! ----------------------------------- -- this makes it wait a certain ammount of time before it really comes on... for 255 loop for 255 loop for 9 loop if mom_switch then -- if switch not pushed then shutdown_pin = off end if end loop end loop end loop shutdown_pin = on -- set portA to normal digital IO -- include 16F628_inc include delay_simple -- the following are some variables that some of the librarys need.. var volatile bit IRP at STATUS : 7 var volatile bit Z at STATUS : 2 var volatile bit C at STATUS : 0 var volatile byte PORTB at 0x06 var volatile bit T0IF at INTCON : 2 var volatile bit T0IE at INTCON : 5 var volatile bit GIE at intcon : 7 var volatile byte _OPTION_REG at 0x81 const LOW_OPTION_REG = 0x81 const HIGH_OPTION_REG = 0 var volatile bit _T0CS at _OPTION_REG : 5 const _b_T0CS = 1 << 5 var volatile bit _PSA at _OPTION_REG : 3 const _b_PSA = 1 << 3 include indf_bits procedure OPTION_REG'put( byte in x ) is _file_put( high_OPTION_REG, low_OPTION_REG, x ) end procedure function OPTION_REG'get return byte is var byte x _file_get( high_OPTION_REG, low_OPTION_REG, x ) return x end function var volatile bit PEIE at INTCON : 6 var volatile bit INTE at INTCON : 4 var volatile bit RBIE at INTCON : 3 var volatile bit INTF at INTCON : 1 var volatile bit RBIF at INTCON : 0 const LOG_ACCURACY = 3 -- sorry don't know another way to do this (needed in byte3_math) include byte3_math -- include smb1theme include play_music1_ins -- include indiana -- include imperial -- END LIBRARYS -- ---------------------------- Variable Setup -------------------------------- var bit encoder_flag = off -- Flag that determines change of encoder state var byte encoder_out = 0 -- Output from the encoder 0 - 255 var bit add_flag -- tells some other procedure if the encoder was last added to var byte encoder_speed var byte encoder_outs -- encoder_out speed calcualted var byte timer = 254 -- timers for rotary encoder var byte scratch_up = 0-- counter for the switch var byte scratch_up2 = 0-- second counter for switch var byte red = 0 -- red LED output, 0 - 255 PWM controlled brightness var byte green = 0 -- green LED output, 0 - 255 PWM controlled brightness var byte blue = 0 -- blue LED output, 0 - 255 PWM controlled brightness var byte red1 = 128 -- temp/shadow -- for the pwm generation var byte green1 = 128 -- var byte blue1 = 128 -- -- var byte hue_in = 0 -- var byte sat_in = 0 var bit white_mode = true var bit mode_change -- has the mode just been changed? var bit get_mode = on -- is the mode currently being changed? var byte mode = 1 -- the current mode, as set by the encoder, when in mode change setting var byte encoder_code1 = 0 -- part of the procedure for getting into advanced mode var byte encoder_code2 = 0 -- same var bit advanced_mode = off -- is the advanced mode turned on or off? var byte encoder_temp = 0 -- Advanced mode variables -- some variables that the advanced mode changes var bit sound_on = on -- is the sound turned on ? var byte voltage_controll_temp = 0 -- temp so value can be stored in eeprom var byte current_controll_temp = 0 -- the advanced mode also plays a song :P thats the third option var byte advanced_flag = 20 -- some weird value so it knows its the first time in this mode var byte encoder_temp2 = 0 -- to tell the advanced mode wether or not the encoder has moved -- some variables that the normal mode changes var byte hue = 42 -- Hue: red = 42, green = 127, blue = 212 var byte hue_preset -- indirect access to the hue variable var byte sat = 0 -- Saturation: 255 = white, 0 = full color saturation var byte sat_preset var byte bright = 255 -- Brightness: 0 = all off, 255 = all on, or 100% brightness var byte bright_preset var byte speed = 0 -- speed variable var byte speed_scratch = 0 -- timer scratch for speed mode var byte mode_flag = 20 -- if a new mode is chosen, change the encoder value to current mode value var byte tone = 20 -- tone of the beeps var byte bright_temp = 0 var byte bright_temp2 = 0 var byte hue_temp = hue var byte hue_scratch = 1 -- part of the hue calc -- These variables are for the 24 bit (3 byte) calculations -- byte3_declare c -- color ;;;;;<;mac> byte3_declare s var byte s1,s2,s3 ;;;;;<;/mac> ;;;;;<;mac> byte3_declare temp var byte temp1,temp2,temp3 ;;;;;<;/mac> -- byte3_declare temp_ ;;;;;<;mac> byte3_declare b -- brightness var byte b1,b2,b3 ;;;;;<;/mac> -- ---------------Set Some Variables according to the EEPROM ------------------- eeprom_get(2, hue_preset) eeprom_get(3, sat_preset) eeprom_get(4, bright_preset) eeprom_get(5, voltage_controll_temp) eeprom_get(6, tone) eeprom_get(7, current_controll_temp) if voltage_controll_temp == 1 then voltage_controll = off -- change to 5v mode else voltage_controll = on end if if current_controll_temp == 1 then current_controll = on -- change to 5v mode else current_controll = off end if -- --------------------- PWM SETUP ------------------------------------ -- The PWM signal osciliates at about 70 HZ -- defines how many PWM outputs there are, in this case there are three const pwm_motors = 0b_0000_0111 -- define to which pin each motor is connected, -- all 8 ouputs -- not used outputs must still be defined ;;;;;<;mac> io_pin pwm1_pin = pin_b0 var volatile bit pwm1_pin_pin is pin_b0 var volatile byte pwm1_pin_port is portb const pwm1_pin_nr = 0 var volatile byte pwm1_pin_buffer is _port_b_buffer var volatile bit pwm1_pin_direction is pin_b0_direction ;;;;;<;/mac> ;;;;;<;mac> io_pin pwm2_pin = pin_b1 var volatile bit pwm2_pin_pin is pin_b1 var volatile byte pwm2_pin_port is portb const pwm2_pin_nr = 1 var volatile byte pwm2_pin_buffer is _port_b_buffer var volatile bit pwm2_pin_direction is pin_b1_direction ;;;;;<;/mac> ;;;;;<;mac> io_pin pwm3_pin = pin_b2 var volatile bit pwm3_pin_pin is pin_b2 var volatile byte pwm3_pin_port is portb const pwm3_pin_nr = 2 var volatile byte pwm3_pin_buffer is _port_b_buffer var volatile bit pwm3_pin_direction is pin_b2_direction ;;;;;<;/mac> ;;;;;<;mac> io_pin pwm4_pin = pin_b2 var volatile bit pwm4_pin_pin is pin_b2 var volatile byte pwm4_pin_port is portb const pwm4_pin_nr = 2 var volatile byte pwm4_pin_buffer is _port_b_buffer var volatile bit pwm4_pin_direction is pin_b2_direction ;;;;;<;/mac> ;;;;;<;mac> io_pin pwm5_pin = pin_b2 var volatile bit pwm5_pin_pin is pin_b2 var volatile byte pwm5_pin_port is portb const pwm5_pin_nr = 2 var volatile byte pwm5_pin_buffer is _port_b_buffer var volatile bit pwm5_pin_direction is pin_b2_direction ;;;;;<;/mac> ;;;;;<;mac> io_pin pwm6_pin = pin_b2 var volatile bit pwm6_pin_pin is pin_b2 var volatile byte pwm6_pin_port is portb const pwm6_pin_nr = 2 var volatile byte pwm6_pin_buffer is _port_b_buffer var volatile bit pwm6_pin_direction is pin_b2_direction ;;;;;<;/mac> ;;;;;<;mac> io_pin pwm7_pin = pin_b2 var volatile bit pwm7_pin_pin is pin_b2 var volatile byte pwm7_pin_port is portb const pwm7_pin_nr = 2 var volatile byte pwm7_pin_buffer is _port_b_buffer var volatile bit pwm7_pin_direction is pin_b2_direction ;;;;;<;/mac> ;;;;;<;mac> io_pin pwm8_pin = pin_b2 var volatile bit pwm8_pin_pin is pin_b2 var volatile byte pwm8_pin_port is portb const pwm8_pin_nr = 2 var volatile byte pwm8_pin_buffer is _port_b_buffer var volatile bit pwm8_pin_direction is pin_b2_direction ;;;;;<;/mac> -- include the motor library include pwm_motor -- calculate and set TMR0, to the desired resolution of the PWM pwm1_period_preset = 255 -- set the max value for PWM pwm1_active_preset = 128 -- set the starting value to 50% pwm2_period_preset = 255 pwm2_active_preset = 128 -- the LEDs will be at this setting during the startup sequence pwm3_period_preset = 255 pwm3_active_preset = 128 -- ------------------------- BEGIN --------------------------------------------- -- -------------------------------- Shutdown Procedure ------------------------- Procedure shutdown2 is if white_mode then eeprom_put(2, hue_preset) eeprom_put(3, sat_preset) eeprom_put(4, bright_preset) eeprom_put(5, voltage_controll_temp) eeprom_put(6, tone) eeprom_put(7, current_controll_temp) end if red1 = 0 green1 = 0 blue1 = 0 play_tone(5, 10) delay_10ms play_tone(10, 10) delay_10ms play_tone(15, 10) delay_10ms play_tone(20, 10) delay_10ms play_tone(25, 10) delay_10ms play_tone(30, 10) shutdown_pin = off end procedure procedure brightness_calc (byte in out color_in_out2) is -- this procedure basically takes the given color input, and the new desired brightness -- it then scales them proportionatley.. like if the color value was 128 (half of 256) -- and the brightness value was 128 (or 50% ) then b3 = 0 -- make sure all the bytes of the 3 byte variables are clear b2 = 0 temp3 = 0 temp2 = 0 temp1 = color_in_out2 -- set the relevant parts of the variables b1 = bright -- color = (color * brightness) / 255 ;;;;;<;mac> byte3_MUL temp = temp , b -- temp = temp * b ( color = color * brightness) Y1 = temp1 Y2 = temp2 Y3 = temp3 X1 = b1 X2 = b2 X3 = b3 byte3_mul temp1 = Y1 temp2 = Y2 temp3 = Y3 ;;;;;<;/mac> ;;;;;<;mac> byte3_SHR temp , 8 -- temp = temp / 255 ( color = color / 255) Y1 = temp1 Y2 = temp2 Y3 = temp3 byte3_srr (8, false) temp1 = Y1 temp2 = Y2 temp3 = Y3 ;;;;;<;/mac> color_in_out2 = temp1 -- color in and out = brightness calculated color value end procedure -- for this procdure you might think you could just put the saturation calc part -- into another procedure... but for some reason it doesnt work if you do this -- I had it done that way and spent 5 days or so trying to figure out why it wouldnt work -- procedure hue_calc(byte in out color1, byte in out color2, byte in out color3) is color1 = 255 -- blue is fully on if hue <= 127 then -- if hue is less than or equal to the midpoint (128) then color2 = 255 - (hue * 2) -- color1,2,3 are NOT 3 byte variables s2 = 0 s3 = 0 s1 = sat temp1 = 255 - color2 -- only the parts of the math that need 3 bytes are done with the byte3 routines ;;;;; <;mac> byte3_MUL temp = temp , s -- temp = temp * s = (255-c)*s Y1 = temp1 Y2 = temp2 Y3 = temp3 X1 = s1 X2 = s2 X3 = s3 byte3_mul temp1 = Y1 temp2 = Y2 temp3 = Y3 ;;;;;<;/mac> ;;;;; <;mac> byte3_SHR temp , 8 -- temp = temp /128 = (255-c)*s/256 Y1 = temp1 Y2 = temp2 Y3 = temp3 byte3_srr (8, false) temp1 = Y1 temp2 = Y2 temp3 = Y3 ;;;;;<;/mac> color2 = color2 + temp1 -- c = c + temp = c+(255-c)*s/256 color3 = sat else -- if hue is greater than the midpoint (128) then color3 = (hue - 128) * 2 -- calc hue -- Begin SATURATION calc s2 = 0 s3 = 0 s1 = sat temp1 = 255 - color3 -- only the parts of the math that need 3 bytes are done with the byte3 routines ;;;;; <;mac> byte3_MUL temp = temp , s -- temp = temp * s = (255-c)*s Y1 = temp1 Y2 = temp2 Y3 = temp3 X1 = s1 X2 = s2 X3 = s3 byte3_mul temp1 = Y1 temp2 = Y2 temp3 = Y3 ;;;;;<;/mac> ;;;;; <;mac> byte3_SHR temp , 8 -- temp = temp /128 = (255-c)*s/256 Y1 = temp1 Y2 = temp2 Y3 = temp3 byte3_srr (8, false) temp1 = Y1 temp2 = Y2 temp3 = Y3 ;;;;;<;/mac> color3 = color3 + temp1 -- c = c + temp = c+(255-c)*s/256 -- END saturation calc color2 = sat end if end procedure -- The Hue can only be incremented by one either up or down in each cycle... -- there is a special procedure to up the speed of the encoder, wihtout compromizing this parameter -- There are 765 different hues in this version -- But you cannot just set the hue to any value you want.... with one variable at least -- you can set the hue_scratch and the hue value to achieve any hue.. -- or just increment the hue one at a time and it will automatically increment the hue_scratch value -- I used to have all the hues as one 8 bit variable.. it worked just fine, but i wanted more resolution. procedure hue_sat is if hue_scratch > 3 then hue_scratch = 1 end if if hue_scratch == 1 then -- check to see if its the first part if hue == 0 then if hue_temp == 1 then hue_scratch = 3 -- hue_calc(blue, green, red) elsif hue_temp == 255 then hue_scratch = 2 -- hue_calc(green, red, blue) end if else hue_calc(red, blue, green) -- always on, low, high value end if elsif hue_scratch == 2 then if hue == 0 then if hue_temp == 1 then hue_scratch = 1 -- hue_calc(red, blue, green) elsif hue_temp == 255 then hue_scratch = 3 -- hue_calc(blue, green, red) end if else hue_calc(green, red, blue) end if elsif hue_scratch == 3 then if hue == 0 then if hue_temp == 1 then hue_scratch = 2 -- hue_calc(green, red, blue) elsif hue_temp == 255 then hue_scratch = 1 -- hue_calc(red, blue, green) end if else hue_calc(blue, green, red) end if end if hue_temp = hue end procedure -- --------------------------------- Encoder Reading --------------------------- Procedure read_encoder is -- 2 BIT 24 DETENT, ROTARY ENCODER reading procedure if encoder_b then -- if the B bit of the encoder is on then if encoder_flag == off & encoder_a then -- if bit B was off previous cycle, and Bit A = on add_flag = true encoder_speed = timer encoder_out = encoder_out + 1 -- if not recently activated, just incremnt by 1 encoder_outs = encoder_outs + 1 timer = 255 -- reset the timer end if encoder_flag = on -- turn the flag on so it knows bit B was just off end if if encoder_b == off then -- same but mostly opposite if encoder_flag & encoder_a then add_flag = false encoder_speed = timer -- proportionatly increase speed encoder_out = encoder_out - 1 -- if not recently activated, just incremnt by 1 encoder_outs = encoder_outs - 1 timer = 254 -- reset the timer end if encoder_flag = off end if timer = timer - 1 if timer <= 0 then timer = 1 end if -- if no button press, keep timer low end procedure -- ------------------------- Encoder Speed Calculation ------------------------- procedure calc_encoder_speed is if add_flag then -- if encoder was last added from if encoder_speed > 100 then encoder_speed = encoder_speed - 30 encoder_outs = encoder_outs + 1 end if else -- if encoder was last subtraced from if encoder_speed > 100 then encoder_speed = encoder_speed - 30 encoder_outs = encoder_outs - 1 end if end if end procedure -- ------------------------------ MOM Switch Reading --------------------------- procedure read_switch is if mom_switch == off then -- off means the switch is being pushed if scratch_up == 0 then if white_mode == off then mode = mode + 1 mode_change = on end if end if if scratch_up == 254 then scratch_up = 1 scratch_up2 = scratch_up2 + 1 if scratch_up2 == 1 then if white_mode == off then play_tone (5,20) -- play a little tune delay_10ms play_tone (30 ,20) delay_10ms play_tone (5,20) encoder_outs = 128 -- preset the brightness to 50% white_mode = on else play_tone (30,20) delay_10ms play_tone (5 ,20) delay_10ms play_tone (30,20) white_mode = off mode = 1 -- reset the mode mode_change = on end if end if if scratch_up2 == 3 then shutdown2 end if end if scratch_up = scratch_up + 1 else scratch_up = 0 scratch_up2 = 0 end if end procedure procedure sound_delay(byte in quantity) is -- does beep and delay, high frequency for quantity loop play_tone ( 7 , 20 ) delay_10ms end loop end procedure -- ------------------------------- Should advanced mode be turned on ? --------- -- if you move the encoder minus at least one step, then plus 5, then minus 5 steps, -- the advanced mode will be entered procedure test_encoder_codes is if mode == 3 then -- not tabbed, afterthought has to be in brightness mode to enter advanced if encoder_out == encoder_temp + 1 then encoder_code1 = encoder_code1 + 1 encoder_code2 = 0 elsif encoder_out == encoder_temp - 1 then encoder_code2 = encoder_code2 + 1 if encoder_code1 != 5 then encoder_code1 = 0 else if encoder_code2 == 5 then encoder_code1 = 0 -- reset the codes, just to be sure there is no reentrance encoder_code2 = 0 play_tone(42,20) -- play a little tune so you know the advanced mode is on delay_10ms play_tone(42,20) delay_10ms play_tone(42,20) delay_10ms play_tone(75,20) delay_10ms play_tone(42,20) delay_10ms mode = 0 -- reset the mode advanced_mode = true end if end if end if end if encoder_temp = encoder_out end procedure -- -------------------------------------- MODE SETTING ------------------------- procedure set_mode is -- set the normal mode if mode < 1 then mode = 4 end if if mode > 4 then mode = 1 end if if mode == 1 then -- this mode sets the encoder to the hue value if mode_change then -- if this mode has just been entered sat = sat_preset bright = bright_preset encoder_outs = hue_preset -- so the hue doesnt change when you change the mode sound_delay(1) mode_change = off end if hue_preset = encoder_outs hue = hue_preset elsif mode == 2 then -- this mode sets the encoder to the saturation value if mode_change then hue = hue_preset bright = bright_preset sound_delay(2) encoder_outs = sat_preset mode_change = off end if sat_preset = encoder_outs sat = sat_preset elsif mode == 3 then -- this mode sets the encoder to the brightness value if mode_change then hue = hue_preset sat = sat_preset sound_delay(3) encoder_outs = bright_preset mode_change = off end if bright_preset = encoder_outs bright = bright_preset test_encoder_codes -- see if the advanced mode is on or off elsif mode == 4 then -- this mode will scan through the colors, at a speed determined by the encoder if mode_change then sound_delay(4) sat = sat_preset encoder_out = 1 bright = bright_preset mode_change = off end if speed = encoder_out / 2 -- the speed is already low enough if speed < speed_scratch then speed_scratch = 0 hue = hue + 1 end if speed_scratch = speed_scratch + 1 end if end procedure -- -------------------------------- Set the advanced mode ---------------------- procedure set_advanced_mode is if mode < 1 then mode = 6 end if if mode > 6 then mode = 1 end if if mode == 1 then -- turn the beeps between modes in normal mode on and off if mode_change then sound_delay(1) encoder_outs = tone mode_change = off end if if encoder_outs > 50 then encoder_outs = 0 end if -- the tone is already low enough if encoder_outs < 0 then encoder_outs = 50 end if if tone != encoder_outs then play_tone(tone, 20) end if tone = encoder_outs elsif mode == 2 then -- make the dc-dc output voltage 4v or 5v if mode_change then hue = hue_preset sat = sat_preset bright = bright_preset sound_delay(2) mode_change = off end if if encoder_out == encoder_temp2 + 1 then play_tone(5,20) voltage_controll_temp = 1 elsif encoder_out == encoder_temp2 - 1 then play_tone(30,20) voltage_controll_temp = 0 end if if voltage_controll_temp == 1 then voltage_controll = off -- change to 5v mode else voltage_controll = on end if elsif mode == 3 then -- make the dc-dc output current .5A or 1A if mode_change then hue = hue_preset sat = sat_preset bright = bright_preset sound_delay(3) mode_change = off end if if encoder_out == encoder_temp2 + 1 then play_tone(5,20) current_controll_temp = 1 elsif encoder_out == encoder_temp2 - 1 then play_tone(30,20) current_controll_temp = 0 end if if current_controll_temp == 1 then current_controll = on -- change to 1A mode else current_controll = off -- change to 500ma mode end if elsif mode == 4 then -- play a song ;) if mode_change then hue = hue_preset sat = sat_preset bright = bright_preset sound_delay(4) mode_change = off end if if encoder_out == encoder_temp2 + 1 then play_tone(5,20) play_tune(1) elsif encoder_out == encoder_temp2 - 1 then play_tone(30,20) end if elsif mode == 5 then if mode_change then sound_delay(5) hue = hue_preset sat = sat_preset encoder_outs = 1 mode_change = off end if if encoder_outs < speed_scratch then bright = 255 else bright = 0 end if speed_scratch = speed_scratch + 1 elsif mode == 6 then -- if mode_change then sound_delay(6) encoder_outs = 0 hue = 128 -- set the color to the middle, so that just one LED is on sat = 0 mode_change = off end if if speed < speed_scratch then bright_temp = bright_temp + 1 -- increment the brightness bright_temp2 = bright_temp2 + 1 if bright_temp == 255 then bright_temp2 = 0 hue_scratch = hue_scratch + 1 -- increment the color, red, green, blue end if if bright_temp2 == 10 then bright = bright_temp else bright = 0 end if if bright_temp2 == 12 then bright = bright_temp bright_temp2 = 0 else bright = 0 end if end if speed_scratch = speed_scratch + encoder_outs end if encoder_temp2 = encoder_out end procedure procedure get_mode_encoder is -- NOT USED if encoder_out < 1 then encoder_out = 6 end if if encoder_out > 6 then encoder_out = 1 end if mode = encoder_out sat = 0 bright = 128 if mode == 1 then -- change the output color so you know what mode it is sound_delay(1) -- hue_scratch = 1 -- hue = 128 -- red elsif mode == 2 then -- hue_scratch = 1 -- hue = 255 -- yellow (red/green) elsif mode == 3 then -- hue_scratch = 2 -- hue = 128 -- green elsif mode == 4 then -- hue_scratch = 2 -- hue = 255 -- aqua (green/blue) elsif mode == 5 then -- hue_scratch = 3 -- hue = 128 -- blue elsif mode == 6 then -- hue_scratch = 3 -- hue = 255 -- magic pink (blue/red end if end procedure ;;;;;<;mac> interrupt_main -- interrupt routene -- part of the PWM procedure xzxzxzxz is pragma interrupt if t0if then _tmr0_interrupt ;priority=5 end if end procedure ;;;;;<;/mac> -- ------------------------------ Main Program ------------------------------ forever loop -- START MAIN PROGRAM read_switch -- read the momentary contact switch read_encoder -- check to see if the encoder is being used, perform the necessary adjustments if white_mode then sat = 255 -- make the color white bright = encoder_outs else if advanced_mode then set_advanced_mode -- set the advanced options else set_mode -- set the normal modes end if end if hue_sat -- set the Hue and Saturation calc_encoder_speed -- set the accelerated spped value brightness_calc(red) -- the brightness must be calculated for each color brightness_calc(green) brightness_calc(blue) red1 = red -- set the color shadow values to the real ones green1 = green -- this has to be done this way so that all the calculations blue1 = blue -- have been completed... because the pwm is on an interrupt end loop -- END MAIN PROGRAM