From 4064a2b0d88c8bd21afe1de7cc4f581e0d8281d0 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 12 Sep 2022 21:36:37 -0400 Subject: [PATCH] Reworked IR code so it's 32 bits. Added comments. Added start/stop bit logic. --- src/main.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3c768b5..8c77e26 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,14 @@ #include #include -#include +#include -// unsigned long CODE = 0b10011111111100100100100100100100100100111111001110010010010010011; //65 bits -int code = 111111111000000001111112111000011 ; +//32 bit code +int code = 0b11111111100000000111111011100001; + +//length of each bit #define BIT_LENGTH 10 +//Generates the carrier requency for the supplied timeframe void carrier(int BlastTime) { for(int i=0; i<(BlastTime / 2); i++) { @@ -17,20 +20,31 @@ void carrier(int BlastTime) { return; } +// send '1' bit int sendShort(void){ carrier(BIT_LENGTH); _delay_ms(BIT_LENGTH); return 0; } +// send '0/ bit int sendLong(void){ + _delay_ms(BIT_LENGTH); carrier(BIT_LENGTH); - _delay_ms(BIT_LENGTH*3); + _delay_ms(BIT_LENGTH); + return 0; } +//Send the entire code including init, start, and end bits void sendBlast(void) { carrier(20); _delay_ms(20); + + //start bit + sendShort(); + _delay_ms(BIT_LENGTH); + + //Start 32 bit Code for (int i=0; i<9;i++){ sendShort(); } @@ -40,7 +54,6 @@ void sendBlast(void) { for (int i=0;i<6;i++){ sendShort(); } - _delay_ms(BIT_LENGTH); for (int i=0;i<3;i++){ sendShort(); } @@ -50,8 +63,8 @@ void sendBlast(void) { for(int i=0;i<2;i++){ sendShort(); } - - + //stop bit + sendShort(); } int main(void) { @@ -62,14 +75,12 @@ int main(void) { while(true) { - if ((PINB & (1 << 0x01)) == 0) - { + if ((PINB & (1 << 0x01)) == 0){ //if the button is pushed start sending code sendBlast(); } else { - PORTB &= ~(1 << 0x04); + PORTB &= ~(1 << 0x04); //if the button is not pushed make sure PB4 is off } } - }