mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Run new astyle formatter against all the examples
This commit is contained in:
@ -1,18 +1,18 @@
|
||||
/*
|
||||
Serial Call and Response
|
||||
Language: Wiring/Arduino
|
||||
|
||||
|
||||
This program sends an ASCII A (byte of value 65) on startup
|
||||
and repeats that until it gets some data in.
|
||||
Then it waits for a byte in the serial port, and
|
||||
Then it waits for a byte in the serial port, and
|
||||
sends three sensor values whenever it gets a byte in.
|
||||
|
||||
|
||||
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
|
||||
|
||||
|
||||
The circuit:
|
||||
* potentiometers attached to analog inputs 0 and 1
|
||||
* potentiometers attached to analog inputs 0 and 1
|
||||
* pushbutton attached to digital I/O 2
|
||||
|
||||
|
||||
Created 26 Sept. 2005
|
||||
by Tom Igoe
|
||||
modified 24 April 2012
|
||||
@ -38,7 +38,7 @@ void setup()
|
||||
}
|
||||
|
||||
pinMode(2, INPUT); // digital sensor is on digital pin 2
|
||||
establishContact(); // send a byte to establish contact until receiver responds
|
||||
establishContact(); // send a byte to establish contact until receiver responds
|
||||
}
|
||||
|
||||
void loop()
|
||||
@ -48,17 +48,17 @@ void loop()
|
||||
// get incoming byte:
|
||||
inByte = Serial.read();
|
||||
// read first analog input, divide by 4 to make the range 0-255:
|
||||
firstSensor = analogRead(A0)/4;
|
||||
firstSensor = analogRead(A0) / 4;
|
||||
// delay 10ms to let the ADC recover:
|
||||
delay(10);
|
||||
// read second analog input, divide by 4 to make the range 0-255:
|
||||
secondSensor = analogRead(1)/4;
|
||||
secondSensor = analogRead(1) / 4;
|
||||
// read switch, map it to 0 or 255L
|
||||
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
|
||||
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
|
||||
// send sensor values:
|
||||
Serial.write(firstSensor);
|
||||
Serial.write(secondSensor);
|
||||
Serial.write(thirdSensor);
|
||||
Serial.write(thirdSensor);
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,15 +115,15 @@ void serialEvent(Serial myPort) {
|
||||
int inByte = myPort.read();
|
||||
// if this is the first byte received, and it's an A,
|
||||
// clear the serial buffer and note that you've
|
||||
// had first contact from the microcontroller.
|
||||
// had first contact from the microcontroller.
|
||||
// Otherwise, add the incoming byte to the array:
|
||||
if (firstContact == false) {
|
||||
if (inByte == 'A') {
|
||||
if (inByte == 'A') {
|
||||
myPort.clear(); // clear the serial port buffer
|
||||
firstContact = true; // you've had first contact from the microcontroller
|
||||
myPort.write('A'); // ask for more
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Add the latest byte from the serial port to array:
|
||||
serialInArray[serialCount] = inByte;
|
||||
|
Reference in New Issue
Block a user