Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // K-Digital Remote Outlet control
- // Connect pin 13 to the 433MHz RF Kit transmitter data pin
- #define SIG_BITS 24U
- // Signals for button "1": Last three bits are 111
- uint8_t on_sig[SIG_BITS] = {0,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,1,1,1,1};
- uint8_t off_sig[SIG_BITS] = {0,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1};
- uint8_t all_off_sig[SIG_BITS] = {0,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0};
- void _sendSignalOnce(uint8_t *p) {
- uint8_t n;
- uint16_t uS;
- // Transmit actual bits
- for (n = 0 ; n < SIG_BITS ; n++) {
- if (0 == *p++) {
- uS = 300;
- } else {
- uS = 900;
- }
- digitalWrite(13, HIGH);
- delayMicroseconds(uS);
- digitalWrite(13, LOW);
- delayMicroseconds(1200 - uS);
- }
- // "Stop" signal
- digitalWrite(13, HIGH);
- delayMicroseconds(300);
- digitalWrite(13, LOW);
- }
- // Send the signal multiple times to emulate a press
- void sendSignal(uint8_t *p, uint8_t times) {
- while (times--) {
- _sendSignalOnce(p);
- // Inter-transmission delay
- delay(10);
- }
- }
- void setup() {
- pinMode(13, OUTPUT);
- // "Associate" transmission
- sendSignal(on_sig, 6);
- }
- void loop() {
- // Power outlet Blinky!
- sendSignal(on_sig, 2);
- delay(3000);
- sendSignal(off_sig, 2);
- delay(3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement