Code Club Electronics 11
I am now combining a LED blink routine, with reading the potentiometer value input.
// the setup function runs once when you press reset or power the board
float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
// read the input on analog pin A0:
int analogValue = analogRead(A0);
// Rescale to potentiometer's voltage (from 0V to 5V):
float voltage = floatMap(analogValue, 0, 1023, 0, 5);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(analogValue); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(analogValue); // wait for a second
}
Video
Video illustrates how rotation of the potentiometer is reflected in the LED blink delay.
Links
Tags
#Electronics,#Code,#Arduino,#Hacking.#TempSensor
Mastodon | Peertube | Join Mastodon |
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.