Created
April 2, 2020 08:08
-
-
Save todocono/2fb93db53ac1b052d160acca8f40b509 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 17 - Digital & Analog | |
* Ideas for exercises to practice: | |
* try changing the logic: the button controls the time; the potentiometer controls if it works or not | |
* change the pin number of the components | |
* add a second LED | |
* | |
* Based on AnalogReadSerial - http://www.arduino.cc/en/Tutorial/AnalogReadSerial | |
* This example code is in the public domain. | |
*/ | |
const int led = 13; | |
const int btn = 7; | |
const int pot = A0; | |
// the setup routine runs once when you press reset: | |
void setup() { | |
// initialize serial communication at 9600 bits per second: | |
Serial.begin(9600); | |
pinMode(13, OUTPUT); | |
pinMode(btn, INPUT); | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
// read the input on analog pin 0: | |
int sensorValue = analogRead(pot); | |
boolean buttonValue = digitalRead(btn); | |
// print out the value you read: | |
Serial.println(sensorValue); | |
if ( btn == HIGH) { | |
digitalWrite(led, HIGH); | |
delay(sensorValue); | |
digitalWrite(led, LOW); | |
delay(sensorValue); | |
} else { | |
digitalWrite(led, LOW); | |
} | |
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