Added code for example GitHub sketches
This commit is contained in:
parent
0c19ac1e02
commit
2398ffe698
|
|
@ -0,0 +1,48 @@
|
|||
/* HomeSpan Remote Control Example */
|
||||
|
||||
#include "HomeSpan.h" // include the HomeSpan library
|
||||
#include "extras/RFControl.h" // include RF Control Library
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200); // start the Serial interface
|
||||
Serial.flush();
|
||||
delay(1000); // wait for interface to flush
|
||||
|
||||
Serial.print("\n\nHomeSpan RF Transmitter Example\n\n");
|
||||
|
||||
RFControl rf(LED_BUILTIN); // create an instance of RFControl with signal output to the ESP32's Built-In LED
|
||||
|
||||
rf.clear(); // clear the pulse train memory buffer
|
||||
|
||||
rf.add(5000,5000); // create a pulse train with three 5000-tick high/low pulses
|
||||
rf.add(5000,5000);
|
||||
rf.add(5000,10000); // double duration of final low period
|
||||
|
||||
Serial.print("Starting 4 cycles of three 500 ms on pulses...");
|
||||
|
||||
rf.start(4,100); // start transmission of 4 cycles of the pulse train with 1 tick=100 microseconds
|
||||
|
||||
Serial.print("Done!\n");
|
||||
|
||||
delay(2000);
|
||||
|
||||
rf.clear();
|
||||
|
||||
for(int i=1000;i<10000;i+=1000)
|
||||
rf.add(i,10000-i);
|
||||
rf.add(10000,10000);
|
||||
|
||||
Serial.print("Starting 3 cycles of 100-1000 ms pulses...");
|
||||
|
||||
rf.start(3,100); // start transmission of 3 cycles of the pulse train with 1 tick=100 microseconds
|
||||
|
||||
Serial.print("Done!\n");
|
||||
|
||||
Serial.print("\nEnd Example");
|
||||
|
||||
} // end of setup()
|
||||
|
||||
void loop(){
|
||||
|
||||
} // end of loop()
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/* HomeSpan Table Lamp Example */
|
||||
|
||||
#include "HomeSpan.h" // include the HomeSpan library
|
||||
|
||||
struct TableLamp : Service::LightBulb{
|
||||
|
||||
int lampPin; // store the pin number connected to a hypothetical relay that turns the Table Lamp on/off
|
||||
SpanCharacteristic *lampPower; // store a reference to the On Characteristic
|
||||
|
||||
TableLamp(int lampPin) : Service::LightBulb(){ // constructor() method for TableLamp defined with one parameter. Note we also call the constructor() method for the LightBulb Service.
|
||||
|
||||
lampPower=new Characteristic::On(); // instantiate the On Characteristic and save it as lampPower
|
||||
this->lampPin=lampPin; // save the pin number for the hypothetical relay
|
||||
pinMode(lampPin,OUTPUT); // configure the pin as an output using the standard Arduino pinMode function
|
||||
|
||||
} // end constructor()
|
||||
|
||||
boolean update(){ // update() method
|
||||
|
||||
digitalWrite(lampPin,lampPower->getNewVal()); // use standard Arduino digitalWrite function to change the ledPin to either high or low based on the value requested by HomeKit
|
||||
|
||||
return(true); // return true to let HomeKit (and the Home App Client) know the update was successful
|
||||
|
||||
} // end update()
|
||||
|
||||
};
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200); // start the Serial interface
|
||||
|
||||
homeSpan.begin(); // initialize HomeSpan
|
||||
|
||||
new SpanAccessory(); // Table Lamp Accessory
|
||||
|
||||
new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, with 6 *required* Characteristics
|
||||
new Characteristic::Name("My Table Lamp"); // Name of the Accessory, which shows up on the HomeKit "tiles", and should be unique across Accessories
|
||||
new Characteristic::Manufacturer("HomeSpan"); // Manufacturer of the Accessory (arbitrary text string, and can be the same for every Accessory)
|
||||
new Characteristic::SerialNumber("123-ABC"); // Serial Number of the Accessory (arbitrary text string, and can be the same for every Accessory)
|
||||
new Characteristic::Model("120-Volt Lamp"); // Model of the Accessory (arbitrary text string, and can be the same for every Accessory)
|
||||
new Characteristic::FirmwareRevision("0.9"); // Firmware of the Accessory (arbitrary text string, and can be the same for every Accessory)
|
||||
new Characteristic::Identify(); // Provides a hook that allows a HomeKit Client to identify the device
|
||||
|
||||
new Service::HAPProtocolInformation(); // HAP requires every Accessory (except those in a bridge) to implement a Protcol Information Service
|
||||
new Characteristic::Version("1.1.0"); // Set the Version Characteristic to "1.1.0," which is required by HAP
|
||||
|
||||
new TableLamp(17); // instantiate the TableLamp Service (defined below) with lampPin set to 17
|
||||
|
||||
} // end of setup()
|
||||
|
||||
void loop(){
|
||||
|
||||
homeSpan.poll();
|
||||
|
||||
} // end of loop()
|
||||
Loading…
Reference in New Issue