Created
April 7, 2020 04:44
-
-
Save todocono/3c4bc113e5e12ea68d35e4d7ed46684f to your computer and use it in GitHub Desktop.
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
/* | |
IxLab 2020S - NYU Shanghai | |
recorded during class 18 - Programming Arduino | |
Ideas for exercises to practice: | |
get creative with the application of the map function | |
change the pin number of the components | |
add a second potentiometer | |
Based on AnalogReadSerial - http://www.arduino.cc/en/Tutorial/AnalogReadSerial | |
This example code is in the public domain. | |
*/ | |
const int led = 11; | |
const int pot = A0; | |
// the setup routine runs once when you press reset: | |
void setup() { | |
Serial.begin(9600); | |
pinMode(led, OUTPUT); | |
pinMode(pot, INPUT); | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
int sensorValue = analogRead(pot); // read the 10 bits from the analog digital conversion module | |
int ledValue = int(map(sensorValue, 0, 1023, 0, 255)); // the maximum I received is 1023 (10 bits) | |
analogWrite(led, ledValue); //it writes on the PWM module, so it can accept only 8 bits | |
Serial.print(sensorValue); | |
Serial.print(" was mapped to the LED with "); //adds text in between | |
Serial.println(ledValue); // print out the value you write | |
delay(1); // delay in between reads for stability | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment