hi im looking for help building code that will momentarily pulse an led as a pot is turned up at a certain rate like %5 in 100 millisecond or faster and shuts of when the pot is not in motion or turned back down
You will need to be able to:
Read a pot, which I guess you already can-do.
Read and use time values.
Be able to do both "at once".
Please read this tutorial and tell me what you think?
How to do multiple things at once ... like cook bacon and eggs
i checked out that page i got that i need to compare time to the pot value i am a rookie at writing code so i don't know how to formulate that. i haven't found any one who has done this type of sketch yet
Is that all you learned?
Did you simply skim through it looking for what you need for your project?
Sometimes you have to reach a corner to turn it.
Here, you still need to think to go from this to what you want. It's closer but the lesson is less complete.
// Blink With Pot Adjustable Delay
/*
Circuit is a potentiometer with outside legs to 5V and GND, middle to A0
*/
unsigned long startBlink; // because millis() returns unsigned long
unsigned long waitBlink; // because millis() returns unsigned long
const byte ledPin = 13;
byte ledState = LOW; // so the light turns on 1st time through loop()
const byte potPin = A0;
word potVal, lastVal;
void setup()
{
Serial.begin( 115200 ); // getting the serial queue to empty quicker
pinMode( ledPin, OUTPUT );
digitalWrite( ledPin, ledState);
pinMode( potPin, INPUT );
lastVal = potVal = analogRead( potPin );
waitBlink = (unsigned long) potVal;
Serial.println( "Adjustable Blink Without Delay" );
Serial.print( "Initial value: " );
Serial.print( potVal );
Serial.println( "\n" );
}
void loop()
{
if ( millis() - startBlink >= waitBlink ) // welcome to unsigned math
{
ledState = !ledState; // changes 0 to 1, changes 1 to 0
waitBlink = (unsigned long) potVal;
startBlink = millis();
digitalWrite( ledPin, ledState );
}
potVal = analogRead( potPin );
// I had to put a seadzone in because my cheap pot dithers badly
// Note that potVal/waitBlink are not deadzoned, only the report.
if (( potVal - lastVal > 3 ) && ( lastVal - potVal > 3 )) // deadzone
{
lastVal = potVal;
Serial.println( potVal );
// waitBlink = 0UL; // ends the current blink right away
}
}