Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRsend.h>
- #include <Wire.h>
- #define PERIOD 3000
- unsigned long last_reset = 0;
- #define IR_LED 14
- #define SLAVES_RESET 16
- #define BLINK_CODE 0x44444444
- IRsend irsend(IR_LED);
- bool someoneFlashed = false;
- unsigned long timeElapsedSinceLastFlash = 0;
- bool attinyInterruptFlagArray [4] = {false, false,false,false};
- uint8_t attinyAddressArray [4] = {0x10, 0x11, 0x12, 0x13};
- const byte interruptPinFor12 = 10;
- const byte interruptPinFor10 = 2;
- const byte interruptPinFor13 = 13;
- const byte interruptPinFor14 = 0;
- const byte interruptPinFor11 = 15;
- unsigned long flagMillis = 0;
- void ICACHE_RAM_ATTR checkSlave10() {
- flagMillis = millis();
- someoneFlashed = true;
- }
- void ICACHE_RAM_ATTR checkSlave11() {
- flagMillis = millis();
- someoneFlashed = true;
- }
- void ICACHE_RAM_ATTR checkSlave12() {
- flagMillis = millis();
- someoneFlashed = true;
- }
- void ICACHE_RAM_ATTR checkSlave13() {
- flagMillis = millis();
- someoneFlashed = true;
- }
- void ICACHE_RAM_ATTR checkSlave14() {
- }
- void setup() {
- pinMode(SLAVES_RESET, OUTPUT);
- Wire.begin();
- digitalWrite(SLAVES_RESET, LOW);
- delay(10);
- digitalWrite(SLAVES_RESET, HIGH);
- delay(1000);
- pinMode(interruptPinFor10, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(interruptPinFor10), checkSlave10, FALLING);
- pinMode(interruptPinFor11, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(interruptPinFor11), checkSlave11, FALLING);
- pinMode(interruptPinFor12, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(interruptPinFor12), checkSlave12, FALLING);
- pinMode(interruptPinFor13, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(interruptPinFor13), checkSlave13, FALLING);
- pinMode(interruptPinFor14, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(interruptPinFor14), checkSlave14, FALLING);
- for (uint8_t i = 0; i < 10; i++) {
- delay(100);
- for(uint8_t j = 0; j < 4 ; j++) {
- dataFromSlave(attinyAddressArray[j]);
- delay(100);
- }
- }
- pinMode(16, OUTPUT);
- digitalWrite(16, HIGH);
- irsend.begin();
- }
- void loop() {
- if (someoneFlashed)
- {
- timeElapsedSinceLastFlash = flagMillis - last_reset - 100;
- someoneFlashed = false;
- }
- if (millis() >= (last_reset + PERIOD - timeElapsedSinceLastFlash/20))
- {
- last_reset = millis();
- digitalWrite(16, LOW);
- irsend.sendNEC(BLINK_CODE, 32);
- digitalWrite(16, HIGH);
- }
- }
- uint32_t dataFromSlave(uint8_t adrs) {
- delay(10);
- unsigned long value;
- uint8_t returned = Wire.requestFrom(adrs, 4);
- for (uint8_t i = 0; i < returned; i++) {
- uint8_t tmp = Wire.read();
- (i == 0) ? (value = tmp) : (value = value * 256 + tmp);
- }
- return value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement