1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | /* Transmit sketch - RF Calibration Written by ScottC 17 July 2014 Arduino IDE version 1.0.5 Website: http://arduinobasics.blogspot.com Transmitter: FS1000A/XY-FST Description: A simple sketch used to calibrate RF transmission. ------------------------------------------------------------- */
#define rfTransmitPin 4 //RF Transmitter pin = digital pin 4 #define ledPin 13 //Onboard LED = digital pin 13 const int codeSize = 25; //The size of the code to transmit int codeToTransmit[codeSize]; //The array used to hold the RF code int lightON[]={2,2,2,2,1,4,4,4,4,5,1,4,4,4,4,4,4,5,2,2,1,4,4,4,6}; //The RF code that will turn the light ON int lightOFF[]={2,2,2,2,1,4,4,4,4,5,1,4,4,4,4,4,4,5,2,2,2,2,2,2,3}; //The RF code that will turn the light OFF int codeToggler = 0; //Used to switch between turning the light ON and OFF int timeDelay=5; // The variable used to calibrate the RF signal lengths.
void setup(){ Serial.begin(9600); // Turn the Serial Protocol ON pinMode(rfTransmitPin, OUTPUT); //Transmit pin is an output pinMode(ledPin, OUTPUT); //LED initialisation sequence - gives us some time to get ready digitalWrite(ledPin, HIGH); delay(3000); digitalWrite(ledPin, LOW); delay(1000); } void loop(){ toggleCode(); // switch between light ON and light OFF transmitCode(); // transmit the code to RF receiver on the Fan/Light timeDelay+=10; //Increment the timeDelay by 10 microseconds with every transmission delay(2000); //Each transmission will be about 2 seconds apart. } /*---------------------------------------------------------------- toggleCode(): This is used to toggle the code for turning the light ON and OFF -----------------------------------------------------------------*/ void toggleCode(){ if(codeToggler){ for(int i = 0; i<codeSize; i++){ codeToTransmit[i]=lightON[i]; } } else{ for(int i = 0; i<codeSize; i++){ codeToTransmit[i]=lightOFF[i]; } } codeToggler=!codeToggler; } /*----------------------------------------------------------------- transmitCode(): Used to transmit the signal to the RF receiver on the fan/light. There are 6 different HIGH-LOW signal combinations. SH = short high or LH = long high PLUS SL = short low or LL = long low or VLL = very long low -------------------------------------------------------------------*/ void transmitCode(){ // The LED will be turned on to create a visual signal transmission indicator. digitalWrite(ledPin, HIGH); //initialise the variables int highLength = 0; int lowLength = 0; //The signal is transmitted 6 times in succession - this may vary with your remote. for(int j = 0; j<6; j++){ for(int i = 0; i<codeSize; i++){ switch(codeToTransmit[i]){ case 1: // SH + SL highLength=3; lowLength=3; break; case 2: // SH + LL highLength=3; lowLength=7; break; case 3: // SH + VLL highLength=3; lowLength=92; break; case 4: // LH + SL highLength=7; lowLength=3; break; case 5: // LH + LL highLength=7; lowLength=7; break; case 6: // LH + VLL highLength=7; lowLength=92; break; } /* Transmit a HIGH signal - the duration of transmission will be determined by the highLength and timeDelay variables */ digitalWrite(rfTransmitPin, HIGH); delayMicroseconds(highLength*timeDelay); /* Transmit a LOW signal - the duration of transmission will be determined by the lowLength and timeDelay variables */ digitalWrite(rfTransmitPin,LOW); delayMicroseconds(lowLength*timeDelay); } } //Turn the LED off after the code has been transmitted. digitalWrite(ledPin, LOW); } |