-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 60a2cc4
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Solight Arduino library | ||
======================= | ||
|
||
This library enables you to send RF commands to Solight DY01 sockets using 433MHz RF module. | ||
|
||
See example "Blink" - the code is self explaining. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <solight.h> | ||
|
||
Solight solight(8); | ||
|
||
void setup() { | ||
} | ||
|
||
void loop() { | ||
solight.control(31, 'A', 1); | ||
delay(1000); | ||
solight.control(31, 'A', 0); | ||
delay(1000); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "solight.h" | ||
|
||
Solight::Solight(int pin, int transmitCount) : | ||
mPin(pin), | ||
mTransmitCount(transmitCount) | ||
{ | ||
pinMode(mPin, OUTPUT); | ||
} | ||
|
||
void Solight::transmitBit(uint8_t b) { | ||
digitalWrite(mPin, HIGH); | ||
delayMicroseconds(150 + 300*b); | ||
digitalWrite(mPin, LOW); | ||
delayMicroseconds(450 - 300*b); | ||
} | ||
|
||
void Solight::control(uint16_t socketNumber, char state) { | ||
uint16_t tmp; | ||
int i, j; | ||
for(j = 0; j < mTransmitCount; ++j) { | ||
tmp = socketNumber; | ||
// Channel number | ||
for(i = 0; i < 5; ++i) { | ||
transmitBit((tmp / 512) % 2); | ||
transmitBit(1); | ||
tmp *= 2; | ||
} | ||
transmitBit(0); | ||
// Socket ID | ||
for(i = 0; i < 5; ++i) { | ||
transmitBit((tmp / 512) % 2); | ||
transmitBit(0); | ||
tmp *= 2; | ||
} | ||
|
||
// State | ||
transmitBit(state); | ||
transmitBit(0); | ||
transmitBit(!state); | ||
transmitBit(0); | ||
delayMicroseconds(4600); | ||
} | ||
} | ||
|
||
void Solight::control(uint16_t channelNumber, char socketLetter, char state) { | ||
channelNumber *= 32; | ||
switch(socketLetter) { | ||
case 'A': | ||
case 'a': | ||
channelNumber += 31-16; | ||
break; | ||
case 'B': | ||
case 'b': | ||
channelNumber += 31-8; | ||
break; | ||
case 'C': | ||
case 'c': | ||
channelNumber += 31-4; | ||
break; | ||
case 'D': | ||
case 'd': | ||
channelNumber += 31-2; | ||
break; | ||
case 'E': | ||
case 'e': | ||
channelNumber += 31-1; | ||
break; | ||
} | ||
Serial.println(channelNumber); | ||
control(channelNumber, state); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef SOLIGHT_H | ||
#define SOLIGHT_H | ||
|
||
#include "Arduino.h" | ||
|
||
class Solight { | ||
public: | ||
// If you set transmitCount to less than 2, it won't work! | ||
Solight(int pin, int transmitCount = 5); | ||
void control(uint16_t socketNumber, char state); | ||
void control(uint16_t channelNumber, char socketLetter, char state); | ||
private: | ||
void transmitBit(uint8_t b); | ||
int mPin, mTransmitCount; | ||
}; | ||
|
||
#endif |