Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DBGpin 13
- #define TXpin 7
- #define RETRANSMIT 4
- int tOneHigh = 250; //275;
- int tOneLow = 250; //170;
- int tZeroHigh = 250;
- int tZeroLow = 1250;
- int tSyncHigh = 250;
- int tSyncLow = 2500;
- int tPauseHigh = 250;
- int tPauseLow = 10000;
- char *dim[15] = {
- "01010110",
- "01011001",
- "01011010",
- "01100101",
- "01100110",
- "01101001",
- "01101010",
- "10010101",
- "10010110",
- "10011001",
- "10011010",
- "10100101",
- "10100110",
- "10101001",
- "10101010"
- };
- char *On1 = "0101010110011001011010101010011001010101010101011001011001010101";
- void setup() {
- pinMode(TXpin, OUTPUT);
- pinMode(DBGpin, OUTPUT);
- Serial.begin(9600);
- void loop() {
- test();
- // group(on);
- }
- void test() {
- Serial.println("Turn on #1");
- sendPackets(On1);
- delay(100);
- void sendPackets(char *pkt) {
- for (int i = 0; i < RETRANSMIT; i++) {
- sendPacket(pkt);
- }
- Serial.println("");
- }
- void sendPacket(char *pkt) {
- sendSync();
- sendCode(pkt, strlen(pkt));
- sendPause();
- Serial.println("");
- }
- void sendCode(char *str, int len) {
- char *p = str;
- int i = 0;
- while (i <= len) {
- if (*p == '0') {
- sendZero();
- }
- if (*p == '1') {
- sendOne();
- }
- p++;
- i++;
- }
- }
- void sendZero() {
- Serial.print("0");
- digitalWrite(TXpin, HIGH);
- delayMicroseconds(tZeroHigh);
- digitalWrite(TXpin, LOW);
- delayMicroseconds(tZeroLow);
- }
- void sendOne() {
- Serial.print("1");
- digitalWrite(TXpin, HIGH);
- delayMicroseconds(tOneHigh);
- digitalWrite(TXpin, LOW);
- delayMicroseconds(tOneLow);
- }
- // Sync
- void sendSync() {
- Serial.print("S");
- digitalWrite(TXpin, HIGH);
- delayMicroseconds(tSyncHigh);
- digitalWrite(TXpin, LOW);
- delayMicroseconds(tSyncLow);
- }
- // Pause
- void sendPause() {
- Serial.print("P");
- digitalWrite(TXpin, HIGH);
- delayMicroseconds(tPauseHigh);
- digitalWrite(TXpin, LOW);
- delayMicroseconds(tPauseLow);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement