Created
August 14, 2020 01:34
-
-
Save loadix/1590f5d2b5064449e64daf10fddda503 to your computer and use it in GitHub Desktop.
map and constrain
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
// variable global | |
int led = 9; | |
int input = A0; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(led, OUTPUT); | |
} | |
void loop() { | |
// variable local | |
int ldr = analogRead(input); | |
int potMap = map(ldr, 253, 912, 0, 255); | |
int constMap = constrain(potMap, 0, 255); | |
analogWrite(led, constMap); | |
Serial.print("ldr:"); | |
Serial.print(ldr); | |
Serial.print("||"); | |
Serial.print("potMap:"); | |
Serial.print(potMap); | |
Serial.print("||"); | |
Serial.print("constMap:"); | |
Serial.println(constMap); | |
delay(5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment