hi guys im back again with another assignment i got from school. This time it is a windshield wiper that has to have 4 different modes:
- motor off
- Wiper on with a interval(1 sec forward, 1sec backwards then 1.8sec off before looping)
- wiper on with 1sec forward, 1 sec off, 1sec backward, 1sec off before looping.
- wiper on but 4.1 times faster than at mode 3 still 1 sec forward, 1sec backwards then 1.8sec off before looping but the rpm needs to be 4.1 times faster so normaly it would go at power 60 and in this mode the power becomes 255
This can be done with how many buttons as i would like. I first made a flow chart(i dont know if its correct)
and after that i made a code which uses OneButton. I did everything exactly the same as my previous code(other code) which worked fine. The problem I'm running into at the moment is that as soon as it is in 1 of the if statements in my loop code it doesnt want to read any other button i am pressing and I dont know why as it didn't have this problem before with my other code. And yes I know I only have one if statement in my code at the moment, this is because I want to first fix my code before writing the other if statements.
my code:
//Onebuttons aanmaken
#include "OneButton.h" //roept de OneButton library aan zodat deze gebruikt kan worden
OneButton buttonAllesUit(9,true); // OneButton variabelenaam(pinnummer,aan of uit)
OneButton buttonInterval(8,true);
OneButton buttonXmaalsneller(10,true);
OneButton buttonSnelheid1(11,true);
// Constantes
const int Hbrugaan = 2;
const int MotorVoorruit = 3;
const int MototAchteruit = 5;
// Variabelen
int Power = 255; //snelheid waarmee de motor rond draait
int buttonAllesUitstatus = 0;
int buttonIntervalstatus = 0;
int buttonXmaalsnellerstatus = 0;
int buttonSnelheid1status = 0;
void setup()
{
//Input en output aangeven
pinMode(MotorVoorruit,OUTPUT);
pinMode(MototAchteruit,OUTPUT);
pinMode(Hbrugaan,OUTPUT);
//Knoppen binnden aan externe functies
buttonAllesUit.attachClick(RuitenwisserUit);
buttonInterval.attachClick(RuitenwisserInterval);
buttonXmaalsneller.attachClick(RuitenwisserXmaalSneller);
buttonSnelheid1.attachClick(RuitenwisserSnelheid1);
Serial.begin(9600);
}
void loop()
{
//controlleert de status van de knoppen
buttonAllesUit.tick();
buttonInterval.tick();
buttonXmaalsneller.tick();
buttonSnelheid1.tick();
delay(10);
//Ruitenwisser met interval code
if(buttonIntervalstatus==HIGH)
{
// motor gaat vooruit
digitalWrite(Hbrugaan,HIGH); // zet de H-brug aan
analogWrite(MototAchteruit,0);
analogWrite(MotorVoorruit,Power);
delay(1000);
//motor stopt
digitalWrite(Hbrugaan,LOW);
analogWrite(MotorVoorruit,0);
analogWrite(MototAchteruit,0);
delay(1800);
//motor beweegt achteruit
// digitalWrite(Hbrugaan,HIGH);
analogWrite(MotorVoorruit,0);
analogWrite(MototAchteruit,Power);
delay(1000);
//motor stopt
analogWrite(MotorVoorruit,0);
analogWrite(MototAchteruit,0);
digitalWrite(Hbrugaan,LOW);
delay(1800);
}
else{
analogWrite(MotorVoorruit,0);
analogWrite(MototAchteruit,0);
digitalWrite(Hbrugaan,LOW);
}
}
void RuitenwisserInterval()
{
//Alle loops uit zodat er tijdens dat er een andere loop gedaan wordt er zonder
//op de alles uit knop gedrukt kan worden gewisseld kan worden
buttonAllesUitstatus = LOW;
buttonXmaalsnellerstatus = LOW;
buttonSnelheid1status = LOW;
//Start loop voor interval
buttonIntervalstatus = HIGH;
Serial.println("Ruitenwisser gaat met een interval aan");
}
void RuitenwisserUit()
{
buttonIntervalstatus = LOW;
buttonAllesUitstatus = LOW;
buttonXmaalsnellerstatus = LOW;
buttonSnelheid1status = LOW;
Serial.println("Ruitenwisser staat nu uit");
}
void RuitenwisserXmaalSneller()
{
buttonAllesUitstatus = LOW;
buttonSnelheid1status = LOW;
buttonIntervalstatus = LOW;
buttonXmaalsnellerstatus = HIGH;
Serial.println("Ruitenwisser gaat nu op en neer maar dan 4.1x zo snel ");
}
void RuitenwisserSnelheid1()
{
buttonAllesUitstatus = LOW;
buttonXmaalsnellerstatus = LOW;
buttonIntervalstatus = LOW;
buttonSnelheid1status = HIGH;
Serial.println("Ruitenwisser gaat nu op en neer met snelheid 1");
}
The buttons are connected normally with 10k resitor and to the pin described in the code.
The rest of the board so motor,H-bridge and other wires are connected like the picture
with all the black wires on GND and red on the 5V.
I hope someone can help me because i have tried everything i know.