Closed cingolanifede closed 6 years ago
Can you shutters.reset()
in a sketch, just once, so that it cleans the EEPROM to a clean state. Then, flash your sketch again.
It is doing the same. Also i Cleaned the eeprom and flashed the code again. when level reach the 30% i get: Shutters: reached target Shutters: halting Shutters halting. Shutters: notifying level 30 Shutters at 30% Shutters: end of safety delay
Shutters: notifying level 3 Shutters at 3% Shutters: notifying level 2 Shutters at 2% Shutters: notifying level 1 Shutters at 1% Shutters: starting calibration Shutters: calibration is done Shutters: halting Shutters halting. Shutters: notifying level 0 Shutters at 0% Shutters: end of safety delay
Also I'm having this compiler error in the "readInEeprom" function and to test the code I commented.
exit status 1
cannot convert 'char ()[(((sizetype)
Thanks again
Sorry. I figured out that it was a serial port problem, after i send the command the uc received noise and reset the level. The cannot convert 'char ()[(((sizetype)) + 1)]' to 'char' for argument '1' to 'void readInEeprom(char*, byte)' i solved it by removing & in (&storedShuttersState). Closing issue!
Hi Marvin, thanks for sharing your codes. I'm trying to make the example work but when I give a new level the debug is always:
Going to level 50 Shutters: starting move Shutters: going down Shutters going down.
and then it keeps on saying going down... This is the code I am using, the sample of the example just added 2 inputs and 2 outputs to test it. (Using a nodeMCU ) Is anything i am doing wrong? Maybe using the wrong way? Thanks.
include
include
include
const byte eepromOffset = 0; const unsigned long upCourseTime = 15 1000; const unsigned long downCourseTime = 10 1000; const float calibrationRatio = 0.1;
define ON LOW
define OFF HIGH
int oldTrigValue1 = -1; int oldTrigValue2 = -1; / static const uint8_t D0 = 16; static const uint8_t D1 = 5; static const uint8_t D2 = 4; static const uint8_t D3 = 0; static const uint8_t D4 = 2; static const uint8_t D5 = 14; static const uint8_t D6 = 12; static const uint8_t D7 = 13; static const uint8_t D8 = 15; static const uint8_t D9 = 3; static const uint8_t D10 = 1; /
//Pinout const int RELAY1 = 5; //D1; const int RELAY2 = 4; //D2; const int PIN_TECLA1 = 14; //D5; const int PIN_TECLA2 = 12; //D6;
Bounce debouncer = Bounce(); Bounce debouncer2 = Bounce();
void shuttersOperationHandler(Shutters* s, ShuttersOperation operation) { switch (operation) { case ShuttersOperation::UP: Serial.println("Shutters going up."); // TODO: Implement the code for the shutters to go up digitalWrite(RELAY2, OFF); digitalWrite(RELAY1, ON); break; case ShuttersOperation::DOWN: Serial.println("Shutters going down."); // TODO: Implement the code for the shutters to go down digitalWrite(RELAY1, OFF); digitalWrite(RELAY2, ON); break; case ShuttersOperation::HALT: Serial.println("Shutters halting."); // TODO: Implement the code for the shutters to halt digitalWrite(RELAY1, OFF); digitalWrite(RELAY2, OFF); break; } }
void readInEeprom(char* dest, byte length) { for (byte i = 0; i < length; i++) { dest[i] = EEPROM.read(eepromOffset + i); } }
void shuttersWriteStateHandler(Shutters shutters, const char state, byte length) { for (byte i = 0; i < length; i++) { EEPROM.write(eepromOffset + i, state[i]);
ifdef ESP8266
} }
void onShuttersLevelReached(Shutters* shutters, byte level) { Serial.print("Shutters at "); Serial.print(level); Serial.println("%"); }
Shutters shutters;
void setup() { pinMode(RELAY1, OUTPUT); pinMode(RELAY2, OUTPUT); pinMode(PIN_TECLA1, INPUT); // HAY PONERLA A PULL-DOWN pinMode(PIN_TECLA2, INPUT); //HAY QUE PONERLA A PULL-DOWN
debouncer.attach(PIN_TECLA1); debouncer.interval(50); debouncer2.attach(PIN_TECLA2); debouncer2.interval(50);
Serial.begin(9600); delay(100); EEPROM.begin(512); Serial.println(); Serial.println(" Starting ");
char storedShuttersState[shutters.getStateLength()]; //readInEeprom(&storedShuttersState, shutters.getStateLength()); shutters .setOperationHandler(shuttersOperationHandler) .setWriteStateHandler(shuttersWriteStateHandler) .restoreState(storedShuttersState) .setCourseTime(upCourseTime, downCourseTime) .onLevelReached(onShuttersLevelReached) .begin() .setLevel(30); // Go to 30% }
void loop() { debouncer.update(); debouncer2.update(); shutters.loop();
int value1 = debouncer.read(); int value2 = debouncer2.read();
if (value1 != oldTrigValue1) { oldTrigValue1 = value1; Serial.print("Interruptor--Light 1 : "); Serial.println(value1); //shutters.setLevel(100); }
if (value2 != oldTrigValue2) { oldTrigValue2 = value2; Serial.print("Interruptor--Light 2 : "); Serial.println(value2); //shutters.setLevel(0); }
if (Serial.available() > 0) { int level = Serial.parseInt(); Serial.println(shutters.getCurrentLevel()); Serial.print("Going to level "); Serial.println(level); shutters.setLevel(level); } }