int motorPin = 3;
int buttonPin = 7;
int buttonState = 0;
bool buttonPressed;
void setup()
{
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
while (! Serial);
Serial.println("Speed 0 to 255");
pinMode(buttonPin, INPUT);
buttonPressed = false;
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState== HIGH && !buttonPressed)
{
buttonPressed = true;
analogWrite(motorPin, 100);
Serial.println("high and pressed");
}
else if (buttonState == LOW && buttonPressed)
{
buttonPressed = false;
analogWrite(motorPin, 0);
Serial.println(" not pressed and was on");
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .