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
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); | |
} |
0 commenti:
Posta un commento
Nota. Solo i membri di questo blog possono postare un commento.