homing ok, debattement ok
This commit is contained in:
parent
3d525d6a3a
commit
852721ab34
|
@ -52,8 +52,12 @@ AccelStepper myStepper(4, In1, In3, In2, In4);
|
||||||
int prevDimValue=0;
|
int prevDimValue=0;
|
||||||
int newDimValue=0;
|
int newDimValue=0;
|
||||||
char convBuffer[10];
|
char convBuffer[10];
|
||||||
|
const int debattement = 2038 * 5;
|
||||||
|
|
||||||
int pos=0;
|
bool homed=false;
|
||||||
|
// atmega328p pin 26 -> pc3 -> arduino A3;
|
||||||
|
const int homing_pin = A3;
|
||||||
|
int stopCourseBtnState = 0;
|
||||||
|
|
||||||
unsigned long previousMillis = 0;
|
unsigned long previousMillis = 0;
|
||||||
const long tempInterval = 60000;
|
const long tempInterval = 60000;
|
||||||
|
@ -83,10 +87,13 @@ void setup() {
|
||||||
myStepper.setSpeed(200);
|
myStepper.setSpeed(200);
|
||||||
// myStepper.moveTo(2038);
|
// myStepper.moveTo(2038);
|
||||||
// todo make a homing of stepper motor OR find a way to sensorize where it is
|
// todo make a homing of stepper motor OR find a way to sensorize where it is
|
||||||
myStepper.setCurrentPosition(0);
|
// myStepper.setCurrentPosition(0);
|
||||||
|
|
||||||
send(dimmerMsg.set(prevDimValue));
|
pinMode(homing_pin, INPUT);
|
||||||
send(lightMsg.set(1));
|
digitalWrite(homing_pin, HIGH);
|
||||||
|
|
||||||
|
// send(dimmerMsg.set(prevDimValue));
|
||||||
|
// send(lightMsg.set(1));
|
||||||
|
|
||||||
sensors.begin();
|
sensors.begin();
|
||||||
}
|
}
|
||||||
|
@ -119,6 +126,32 @@ void loop() {
|
||||||
// if (myStepper.distanceToGo() == 0)
|
// if (myStepper.distanceToGo() == 0)
|
||||||
// myStepper.moveTo(-myStepper.currentPosition());
|
// myStepper.moveTo(-myStepper.currentPosition());
|
||||||
|
|
||||||
|
|
||||||
|
// stopCourseBtnState = digitalRead(homing_pin);
|
||||||
|
// if (stopCourseBtnState == HIGH){
|
||||||
|
// Serial.print('stopCourseBtnState HIGH');
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (!homed)
|
||||||
|
{
|
||||||
|
myStepper.setSpeed(200);
|
||||||
|
if (myStepper.distanceToGo() == 0) {
|
||||||
|
myStepper.moveTo(myStepper.currentPosition() + 2038); // turn clockwise to go up
|
||||||
|
}
|
||||||
|
stopCourseBtnState = digitalRead(homing_pin);
|
||||||
|
if (stopCourseBtnState == HIGH){
|
||||||
|
Serial.print("stopCourseBtnState is HIGH");
|
||||||
|
// stepper
|
||||||
|
myStepper.stop();
|
||||||
|
myStepper.setCurrentPosition(0);
|
||||||
|
// HA
|
||||||
|
send(dimmerMsg.set(prevDimValue));
|
||||||
|
send(lightMsg.set(1));
|
||||||
|
|
||||||
|
homed=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Move the motor one step
|
// Move the motor one step
|
||||||
if(!myStepper.run()){
|
if(!myStepper.run()){
|
||||||
// release the stepper motor to free power consumption
|
// release the stepper motor to free power consumption
|
||||||
|
@ -158,8 +191,14 @@ void receive(const MyMessage &message) {
|
||||||
Serial.println(newDimValue);
|
Serial.println(newDimValue);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (homed)
|
||||||
|
{
|
||||||
// todo instead of 1 revolution (2038) define how much revolution we want to do for full opening (100% of the dimmer in HA)
|
// todo instead of 1 revolution (2038) define how much revolution we want to do for full opening (100% of the dimmer in HA)
|
||||||
pos = (2038 / 100) * newDimValue;
|
myStepper.setSpeed(400);
|
||||||
|
int pos = (debattement / 100) * newDimValue * -1; // turn counter clock wise to go done
|
||||||
myStepper.moveTo(pos); // move the stepper
|
myStepper.moveTo(pos); // move the stepper
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue