Created
March 9, 2013 17:20
-
-
Save tomjnixon/5124892 to your computer and use it in GitHub Desktop.
Arduino controller for radio controlled sockets based on SC5272; mane are made by Lloyotron.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env = Environment(tools=["default", "arduino"]) | |
env.ConfigureBoard("atmega328") | |
core = env.ArduinoCore() | |
sketch = env.Sketch("test", ["test.cpp", core]) | |
env.Upload(sketch) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
// 10kHz clock | |
#define DELAY_CLOCKS(n) delayMicroseconds((n) * 100) | |
#define PIN 13 | |
void send_pulse(int time_high, int time_low) { | |
digitalWrite(PIN, HIGH); DELAY_CLOCKS(time_high); | |
digitalWrite(PIN, LOW); DELAY_CLOCKS(time_low); | |
} | |
#define F 2 | |
void send_bit(int bit) { | |
switch (bit) { | |
case 0: | |
send_pulse(4, 12); | |
send_pulse(4, 12); | |
return; | |
case 1: | |
send_pulse(12, 4); | |
send_pulse(12, 4); | |
case F: | |
send_pulse(4, 12); | |
send_pulse(12, 4); | |
return; | |
} | |
} | |
void send_sync() { | |
send_pulse(4, 124); | |
} | |
void send_frame(int addr_a, int addr_b, int value) { | |
for (int word = 0; word < 4; word++) { | |
for (int a_bit = 0; a_bit < 4; a_bit++) | |
send_bit(addr_a == a_bit ? 0 : F); | |
for (int b_bit = 0; b_bit < 4; b_bit++) | |
send_bit(addr_b == b_bit ? 0 : F); | |
send_bit(0); | |
send_bit(0); | |
send_bit(0); | |
send_bit(value ? 1 : 0); | |
send_sync(); | |
} | |
} | |
void setup() { | |
pinMode(PIN, OUTPUT); | |
} | |
void loop() { | |
send_frame(0, 0, 1); | |
delay(1000); | |
send_frame(0, 0, 0); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment