You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to control 4 shutters independently, so I extended the code (thx to @ludodoucet for pointing me in the right direction). But there is something strange happening and I don't know where to look.
Here's what I did: I multiplied most of the code by creating multiple shutter instances. "Shutters" is the original instance, shutters1 etc is the multiplied part. So for the moment I have 5 shutters ;-)
When I run the sketch, "shutters" stays at 0%. All other instances works fine.
When I comment out all parts involved "shutters", the problem moves to shutters1. All remaining three work just fine.
So, there is always a problem with the first instance that is not responding as it should. It seems as if whatever first instance is not responding on setLevel, or at least no more than 1%. I can't get my head around it...
#include<Shutters.h>
#include<EEPROM.h>const byte eepromOffset = 0;
const byte eepromOffset1 = 1;
const byte eepromOffset2 = 2;
const byte eepromOffset3 = 3;
const byte eepromOffset4 = 4;
constunsignedlong upCourseTime = 5000;
constunsignedlong downCourseTime = 5000;
constunsignedlong upCourseTime1 = 5000;
constunsignedlong downCourseTime1 = 5000;
constunsignedlong upCourseTime2 = 5000;
constunsignedlong downCourseTime2 = 5000;
constunsignedlong upCourseTime3 = 5000;
constunsignedlong downCourseTime3 = 5000;
constunsignedlong upCourseTime4 = 5000;
constunsignedlong downCourseTime4 = 5000;
constfloat calibrationRatio = 0.1;
int relay1 = 35;
int relay2 = 37;
int relay3 = 39;
int relay4 = 41;
int schakelaar1 = 43;
int schakelaar2 = 45;
int schakelaar3 = 42;
int schakelaar4 = 44;
int schakelaar1State;
int schakelaar2State;
int schakelaar3State;
int schakelaar4State;
//0 defaultvoidshuttersOperationHandler(Shutters* s, ShuttersOperation operation) {
switch (operation) {
case ShuttersOperation::UP:
Serial.println("shutters going up.");
digitalWrite(relay1, LOW);
digitalWrite(relay2, HIGH);
break;
case ShuttersOperation::DOWN:
Serial.println("shutters going down.");
digitalWrite(relay1, HIGH);
digitalWrite(relay2, LOW);
break;
case ShuttersOperation::HALT:
Serial.println("Shutter halted.");
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
break;
}
}
voidreadInEeprom(char* dest, byte length) {
for (byte i = 0; i < length; i++) {
dest[i] = EEPROM.read(eepromOffset + i);
}
}
voidshuttersWriteStateHandler(Shutters* shutters, constchar* state, byte length) {
for (byte i = 0; i < length; i++) {
EEPROM.write(eepromOffset + i, state[i]);
}
}
voidonShuttersLevelReached(Shutters* shutters, byte level) {
Serial.print("shutters at ");
Serial.print(level);
Serial.println("%");
}
Shutters shutters;
//1voidshuttersOperationHandler1(Shutters* s, ShuttersOperation operation) {
switch (operation) {
case ShuttersOperation::UP:
Serial.println("shutters1 going up.");
break;
case ShuttersOperation::DOWN:
Serial.println("shutters1 going down.");
break;
case ShuttersOperation::HALT:
Serial.println("shutters1 halted.");
break;
}
}
voidreadInEeprom1(char* dest, byte length) {
for (byte i = 0; i < length; i++) {
dest[i] = EEPROM.read(eepromOffset1 + i);
}
}
voidshuttersWriteStateHandler1(Shutters* shutters, constchar* state, byte length) {
for (byte i = 0; i < length; i++) {
EEPROM.write(eepromOffset1 + i, state[i]);
}
}
voidonShuttersLevelReached1(Shutters* shutters, byte level) {
Serial.print("shutters1 at ");
Serial.print(level);
Serial.println("%");
}
Shutters shutters1;
//2voidshuttersOperationHandler2(Shutters* s, ShuttersOperation operation) {
switch (operation) {
case ShuttersOperation::UP:
Serial.println("shutters2 going up.");
break;
case ShuttersOperation::DOWN:
Serial.println("shutters2 going down.");
break;
case ShuttersOperation::HALT:
Serial.println("shutters2 halted.");
break;
}
}
voidreadInEeprom2(char* dest, byte length) {
for (byte i = 0; i < length; i++) {
dest[i] = EEPROM.read(eepromOffset2 + i);
}
}
voidshuttersWriteStateHandler2(Shutters* shutters, constchar* state, byte length) {
for (byte i = 0; i < length; i++) {
EEPROM.write(eepromOffset2 + i, state[i]);
}
}
voidonShuttersLevelReached2(Shutters* shutters, byte level) {
Serial.print("shutters2 at ");
Serial.print(level);
Serial.println("%");
}
Shutters shutters2;
//3voidshuttersOperationHandler3(Shutters* s, ShuttersOperation operation) {
switch (operation) {
case ShuttersOperation::UP:
Serial.println("shutters3 going up.");
break;
case ShuttersOperation::DOWN:
Serial.println("shutters3 going down.");
break;
case ShuttersOperation::HALT:
Serial.println("shutters3 halted.");
break;
}
}
voidreadInEeprom3(char* dest, byte length) {
for (byte i = 0; i < length; i++) {
dest[i] = EEPROM.read(eepromOffset3 + i);
}
}
voidshuttersWriteStateHandler3(Shutters* shutters, constchar* state, byte length) {
for (byte i = 0; i < length; i++) {
EEPROM.write(eepromOffset3 + i, state[i]);
}
}
voidonShuttersLevelReached3(Shutters* shutters, byte level) {
Serial.print("shutters3 at ");
Serial.print(level);
Serial.println("%");
}
Shutters shutters3;
//4voidshuttersOperationHandler4(Shutters* s, ShuttersOperation operation) {
switch (operation) {
case ShuttersOperation::UP:
Serial.println("shutters4 going up.");
break;
case ShuttersOperation::DOWN:
Serial.println("shutters4 going down.");
break;
case ShuttersOperation::HALT:
Serial.println("shutters4 halted.");
break;
}
}
voidreadInEeprom4(char* dest, byte length) {
for (byte i = 0; i < length; i++) {
dest[i] = EEPROM.read(eepromOffset4 + i);
}
}
voidshuttersWriteStateHandler4(Shutters* shutters, constchar* state, byte length) {
for (byte i = 0; i < length; i++) {
EEPROM.write(eepromOffset4 + i, state[i]);
}
}
voidonShuttersLevelReached4(Shutters* shutters, byte level) {
Serial.print("shutters4 at ");
Serial.print(level);
Serial.println("%");
}
Shutters shutters4;
voidsetup() {
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(schakelaar1, INPUT_PULLUP);
pinMode(schakelaar2, INPUT_PULLUP);
pinMode(schakelaar3, INPUT_PULLUP);
pinMode(schakelaar4, INPUT_PULLUP);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
Serial.begin(9600);
delay(100);
Serial.println();
Serial.println("*** start shutters ***");
//0 original codechar storedShuttersState[shutters.getStateLength()];
readInEeprom(storedShuttersState, shutters.getStateLength());
shutters
.setOperationHandler(shuttersOperationHandler)
.setWriteStateHandler(shuttersWriteStateHandler)
.restoreState(storedShuttersState)
.setCourseTime(upCourseTime, downCourseTime)
.onLevelReached(onShuttersLevelReached)
.begin()
.setLevel(10);
//shutter 1char storedShuttersState1[shutters1.getStateLength()];
readInEeprom1(storedShuttersState1, shutters1.getStateLength());
shutters1
.setOperationHandler(shuttersOperationHandler1)
.setWriteStateHandler(shuttersWriteStateHandler1)
.restoreState(storedShuttersState1)
.setCourseTime(upCourseTime1, downCourseTime1)
.onLevelReached(onShuttersLevelReached1)
.begin()
.setLevel(10);
//shutter 2char storedShuttersState2[shutters2.getStateLength()];
readInEeprom2(storedShuttersState2, shutters2.getStateLength());
shutters2
.setOperationHandler(shuttersOperationHandler2)
.setWriteStateHandler(shuttersWriteStateHandler2)
.restoreState(storedShuttersState2)
.setCourseTime(upCourseTime2, downCourseTime2)
.onLevelReached(onShuttersLevelReached2)
.begin()
.setLevel(10);
//shutter 3char storedShuttersState3[shutters3.getStateLength()];
readInEeprom3(storedShuttersState3, shutters3.getStateLength());
shutters3
.setOperationHandler(shuttersOperationHandler3)
.setWriteStateHandler(shuttersWriteStateHandler3)
.restoreState(storedShuttersState3)
.setCourseTime(upCourseTime3, downCourseTime3)
.onLevelReached(onShuttersLevelReached3)
.begin()
.setLevel(10);
//shutter 4char storedShuttersState4[shutters4.getStateLength()];
readInEeprom4(storedShuttersState4, shutters4.getStateLength());
shutters4
.setOperationHandler(shuttersOperationHandler4)
.setWriteStateHandler(shuttersWriteStateHandler4)
.restoreState(storedShuttersState4)
.setCourseTime(upCourseTime4, downCourseTime4)
.onLevelReached(onShuttersLevelReached4)
.begin()
.setLevel(10);
}
voidloop() {
shutters.loop();
shutters1.loop();
shutters2.loop();
shutters3.loop();
shutters4.loop();
if (Serial.available() > 0) {
int level = Serial.parseInt();
Serial.print("Goes to level ");
Serial.print(level);
Serial.println(" %");
shutters.setLevel(level);
shutters1.setLevel(level);
shutters2.setLevel(level);
shutters3.setLevel(level);
shutters4.setLevel(level);
}
//on-OFF-on type switch
schakelaar1State = digitalRead(schakelaar1);
schakelaar2State = digitalRead(schakelaar2);
schakelaar3State = digitalRead(schakelaar3);
if (schakelaar1State == LOW) {
shutters.setLevel(0); //MOVE UP
}
elseif (schakelaar2State == LOW) {
shutters.setLevel(80); //MOVE to 80%
}
elseif (schakelaar3State == LOW) {
shutters.setLevel(100); //MOVE to 100%
}
else {
shutters.stop();
}
} //loop ends here
The text was updated successfully, but these errors were encountered:
I want to control 4 shutters independently, so I extended the code (thx to @ludodoucet for pointing me in the right direction). But there is something strange happening and I don't know where to look.
Here's what I did: I multiplied most of the code by creating multiple shutter instances. "Shutters" is the original instance, shutters1 etc is the multiplied part. So for the moment I have 5 shutters ;-)
When I run the sketch, "shutters" stays at 0%. All other instances works fine.
When I comment out all parts involved "shutters", the problem moves to shutters1. All remaining three work just fine.
So, there is always a problem with the first instance that is not responding as it should. It seems as if whatever first instance is not responding on setLevel, or at least no more than 1%. I can't get my head around it...
The text was updated successfully, but these errors were encountered: