Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //mode
- #define SINGLE_OUTPUT 0x4
- //PWM speed steps
- #define PWM_FLT 0x0
- #define PWM_FWD7 0x7
- //channel
- #define CH1 0x0
- //output
- #define RED 0x0
- int IRPin = 13;
- int toggle[4] = {0,0,0,0};
- void setup()
- {
- pinMode(IRPin, OUTPUT);
- digitalWrite(IRPin, LOW);
- }
- void loop()
- {
- SingleOutput(PWM_FWD7, RED, CH1);
- delay(2000);
- SingleOutput(PWM_FLT, RED, CH1);
- delay(2000);
- }
- void pf_send(int code1, int code2)
- {
- int x = 128;
- start_stop_bit();
- while (x)
- {
- oscillationWrite(IRPin, 156);
- if (code1 & x) //high bit
- high_pause();
- else //low bit
- low_pause();
- x >>= 1; //next bit
- }
- x = 128;
- while (x)
- {
- oscillationWrite(IRPin, 156);
- if (code2 & x) // high bit
- high_pause();
- else //low bit
- low_pause();
- x >>= 1; //next bit
- }
- start_stop_bit();
- delay(10);
- }
- void SingleOutput(int pwm, int output, int channel)
- {
- int nib1, nib2, nib3, nib4, i;
- //set nibs
- nib1 = toggle[channel] | channel;
- nib2 = SINGLE_OUTPUT | output;
- nib3 = pwm;
- nib4 = 0xf ^ nib1 ^ nib2 ^ nib3;
- for(i = 0; i < 6; i++)
- {
- message_pause(channel, i);
- pf_send(nib1 << 4 | nib2, nib3 << 4 | nib4);
- }
- if(toggle[channel] == 0)
- toggle[channel] = 8;
- else
- toggle[channel] = 0;
- }
- void start_pause()
- {
- delayMicroseconds(1014);
- }
- void high_pause()
- {
- delayMicroseconds(546);
- }
- void low_pause()
- {
- delayMicroseconds(260);
- }
- void tx_pause()
- {
- delayMicroseconds(156);
- }
- void message_pause(int channel, int count)
- {
- unsigned char a = 0;
- if(count == 0)
- a = 4 - channel + 1;
- else if(count == 1 || count == 2)
- a = 5;
- else if(count == 3 || count == 4)
- a = 5 + (channel + 1) * 2;
- delayMicroseconds(a * 77);
- }
- void start_stop_bit()
- {
- oscillationWrite(IRPin, 156);
- //digitalWrite(IRPin, HIGH);
- //tx_pause();
- //digitalWrite(IRPin, LOW);
- start_pause();
- }
- void oscillationWrite(int pin, int time) {
- for(int i = 0; i <= time/26; i++) {
- digitalWrite(pin, HIGH);
- delayMicroseconds(13);
- digitalWrite(pin, LOW);
- delayMicroseconds(13);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement