Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //- -----------------------------------------------------------------------------------------------------------------------
- // AskSin++
- // 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
- //- -----------------------------------------------------------------------------------------------------------------------
- // define this to read the device id, serial and device type from bootloader section
- // #define USE_OTA_BOOTLOADER
- // number of relays by defining the device
- #define EI_NOTEXTERNAL
- #include <EnableInterrupt.h>
- #include <AskSinPP.h>
- #include <LowPower.h>
- #include <Switch.h>
- // we use a Pro Mini
- // Arduino pin for the LED
- // D4 == PIN 4 on Pro Mini
- #define LED_PIN 4
- // Arduino pin for the config button
- // B0 == PIN 8 on Pro Mini
- #define CONFIG_BUTTON_PIN 8
- #define RELAY1_PIN 14
- #define RELAY2_PIN 15
- #define RELAY3_PIN 16
- #define RELAY4_PIN 17
- #define RELAY5_PIN 7
- #define RELAY6_PIN 9
- #define RELAY7_PIN 6
- #define RELAY8_PIN 5
- // number of available peers per channel
- #define PEERS_PER_CHANNEL 8
- // all library classes are placed in the namespace 'as'
- using namespace as;
- // define all device properties
- const struct DeviceInfo PROGMEM devinfo = {
- {0x42, 0x44, 0x46}, // Device ID
- "papa000000", // Device Serial
- {0x00, 0x03}, // Device Model
- 0x16, // Firmware Version
- as::DeviceType::Switch, // Device Type
- {0x01, 0x00} // Info Bytes
- };
- /**
- Configure the used hardware
- */
- typedef AvrSPI<10, 11, 12, 13> RadioSPI;
- typedef AskSin<StatusLed<LED_PIN>, NoBattery, Radio<RadioSPI, 2> > Hal;
- // setup the device with channel type and number of channels
- typedef MultiChannelDevice<Hal, SwitchChannel<Hal, PEERS_PER_CHANNEL, List0>, 8> SwitchType;
- Hal hal;
- SwitchType sdev(devinfo, 0x20);
- ConfigButton<SwitchType> cfgBtn(sdev);
- void setup () {
- DINIT(57600, ASKSIN_PLUS_PLUS_IDENTIFIER);
- sdev.init(hal);
- sdev.channel(1).init(RELAY1_PIN, false);
- sdev.channel(2).init(RELAY2_PIN, false);
- sdev.channel(3).init(RELAY3_PIN, false);
- sdev.channel(4).init(RELAY4_PIN, false);
- sdev.channel(5).init(RELAY5_PIN, false);
- sdev.channel(6).init(RELAY6_PIN, false);
- sdev.channel(7).init(RELAY7_PIN, false);
- sdev.channel(8).init(RELAY8_PIN, false);
- buttonISR(cfgBtn, CONFIG_BUTTON_PIN);
- HMID devid;
- sdev.getDeviceID(devid);
- for ( uint8_t i = 1; i <= sdev.channels(); ++i ) {
- Peer ipeer(devid, i);
- sdev.channel(i).peer(ipeer);
- }
- sdev.initDone();
- }
- void loop() {
- bool worked = hal.runready();
- bool poll = sdev.pollRadio();
- if ( worked == false && poll == false ) {
- hal.activity.savePower<Idle<> >(hal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment