Jremington are u a carpenter? cuz you nailed it.
as soon as i figured out switch case statements and understood it i updated my code and it works!! so awesome thanks for all the help, sorry for being such a pain.
heres my working code for reference
const int inPin = 3; // tilt switch or button to trigger dc motor
const int outPin = 1; // dc motor
const int buttonPin = 2; //button to change pwm
const int ledPin = 0; // led to know the state of pwm
int pwmvalue = 0;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
int tiltPushCounter = 0;
int tiltState = 0;
int lasttiltState = 0;
void setup()
{
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
digitalWrite(ledPin, LOW);
digitalWrite(outPin, LOW);
}
void loop()
{
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter ++;
} else {
// if the current state is LOW then the button
// wend from on to off:
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
switch (buttonPushCounter) {
case 0:
digitalWrite(outPin, LOW);
break;
case 1:
pwmvalue = 255;
break;
case 2:
pwmvalue = 180;
break;
case 3:
pwmvalue = 100;
break;
case 4:
pwmvalue = 70;
break;
case 5:
buttonPushCounter = 0;
break;
}
// read the pushbutton input pin:
tiltState = digitalRead(inPin);
// compare the buttonState to its previous state
if (tiltState != lasttiltState) {
// if the state has changed, increment the counter
if (tiltState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
tiltPushCounter ++;
}
else {
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lasttiltState = tiltState;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
switch (tiltPushCounter) {
case 0:
digitalWrite(outPin, LOW);
delay(300);
break;
case 1:
analogWrite(outPin, pwmvalue);
delay(300);
break;
case 2:
tiltPushCounter = 0;
break;
}
}