Hello World,
I am new to Arduino and I have a problem I require help with if possible. I have an Arduino Mega 2560 and i am trying to make a PWM Ramp Up. I have and modified the following code from the archives;
#include <Button.h>
Button goButton(7,PULLDOWN);
int ledPin = 13; // LED connected to digital pin 13
byte goPos = 0; //loop counter
void setup()
{
Serial.begin (9600);
pinMode(ledPin = 13, OUTPUT);
}
void loop()
{
if(goButton.isPressed())
{
if (goPos <= 255) {goPos++;}
if(goPos > 255) {goPos = 255;}
analogWrite(ledPin, goPos);
delay(10);
Serial.print(goPos, DEC);
}
}
This performs most of the function I require, however not exactly.
I require to press the button and hold it, and it ramp up to 255 and stay at 255 while the button is pressed, but if the button is released, return to 0 and await until the button is pressed again.
At the moment if the button is pressed and held, it ramps to 255 and then loops over and over 0 to 255. If the button is released, it stays at the number it was at upon release, 128 for example.
Please help
Kind regards
Luke Lawcock