Skip to content

Instantly share code, notes, and snippets.

@andreavitaletti
Last active February 15, 2016 15:54
Show Gist options
  • Save andreavitaletti/6ade4fca94dea21ed1cb to your computer and use it in GitHub Desktop.
Save andreavitaletti/6ade4fca94dea21ed1cb to your computer and use it in GitHub Desktop.
int incomingByte = 0; // for incoming serial data
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 7 as an output.
pinMode(7, OUTPUT);
// set up Serial library at 9600 bps
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
// if incomingByte == '3' ON
if (incomingByte == 51){
Serial.println("ON");
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
}
// if incomingByte == '4' OFF
if (incomingByte == 52){
Serial.println("OFF");
digitalWrite(7, LOW); // turn the LED on (HIGH is the voltage level)
}
}
// read the input on analog pin 1:
int sensorValue = analogRead(A1);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment