Skip to content

Instantly share code, notes, and snippets.

@alvesoaj
Created January 13, 2021 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvesoaj/3ca6182905fa4504489fb9b929eb995b to your computer and use it in GitHub Desktop.
Save alvesoaj/3ca6182905fa4504489fb9b929eb995b to your computer and use it in GitHub Desktop.
int ledPin = 13; // Arduino' inner led
int sigPin = 4; // For sensor signal
int value = 0; // Holds the returned value
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Arduino's led as output
pinMode(sigPin, INPUT); // signal pin as input
}
void loop(){
value = digitalRead(sigPin); // Read the sensor
if (value == HIGH) { // iF HIGH, black area
digitalWrite(ledPin, HIGH); // Turn on the LED
Serial.write("Black"); // Write on console
} else { // Else, white area
digitalWrite(ledPin, LOW); // Turn off the LED
Serial.write("White"); // Write on console
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment