Created
August 1, 2015 21:55
-
-
Save amriunix/742dcfacc45a64f4308e to your computer and use it in GitHub Desktop.
Arduino potentiometer and led problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int potval; | |
int led = 10; | |
void setup() { | |
pinMode(led, OUTPUT); | |
Serial.begin(9600); | |
} | |
void turnled(int potval){ | |
float pv = potval/((1023/10)/10); | |
float lv = ((255/10)/10)*pv; | |
Serial.println(potval); // arduino says 1023 - Ok! | |
Serial.println(pv); //arduino says 102.00 - Normally it's 100 not 102.00 | |
Serial.println(lv); //arduino says 104.00 - Normally it's 255 not 104.00 | |
analogWrite(led, lv); | |
} | |
void loop() { | |
potval = analogRead(A0); | |
turnled(potval); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment