mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Committing individual examples instead of one .zip
This commit is contained in:
32
build/shared/dist/examples/serial_comm/analog_read_send/analog_read_send.pde
vendored
Normal file
32
build/shared/dist/examples/serial_comm/analog_read_send/analog_read_send.pde
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/* Analog Read Send
|
||||
* ----------------
|
||||
*
|
||||
* turns on and off a light emitting diode(LED) connected to digital
|
||||
* pin 13. The amount of time the LED will be on and off depends on
|
||||
* the value obtained by analogRead(). In the easiest case we connect
|
||||
* a potentiometer to analog pin 2. Sends the data back to a computer
|
||||
* over the serial port.
|
||||
*
|
||||
* Created 1 December 2005
|
||||
* copyleft 2005 DojoDave <http://www.0j0.org>
|
||||
* http://arduino.berlios.de
|
||||
*
|
||||
*/
|
||||
|
||||
int potPin = 2; // select the input pin for the potentiometer
|
||||
int ledPin = 13; // select the pin for the LED
|
||||
int val = 0; // variable to store the value coming from the sensor
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
|
||||
Serial.begin(9600); // use the serial port to send the values back to the computer
|
||||
}
|
||||
|
||||
void loop() {
|
||||
val = analogRead(potPin); // read the value from the sensor
|
||||
Serial.println(val); // print the value to the serial port
|
||||
digitalWrite(ledPin, HIGH); // turn the ledPin on
|
||||
delay(val); // stop the program for some time
|
||||
digitalWrite(ledPin, LOW); // turn the ledPin off
|
||||
delay(val); // stop the program for some time
|
||||
}
|
37
build/shared/dist/examples/serial_comm/double_counter/double_counter.pde
vendored
Normal file
37
build/shared/dist/examples/serial_comm/double_counter/double_counter.pde
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
/* Double Counter
|
||||
* --------------
|
||||
*
|
||||
* This program creates a double counter
|
||||
* and sends the information over the port
|
||||
* back to the computer.
|
||||
* It can be used to test the connection of two different
|
||||
* sensors to the board at the same time.
|
||||
*
|
||||
* (cleft) 2005 David Cuartielles for DojoCorp
|
||||
* @author: D. Cuartielles
|
||||
* @credits: Greg and Nima from SFU
|
||||
*/
|
||||
|
||||
int count = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// counter A will go forwards
|
||||
Serial.print('A');
|
||||
Serial.print(count);
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
|
||||
// counter B will go backwards
|
||||
Serial.print('B');
|
||||
Serial.print(1024 - count);
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
|
||||
// increase and reset the counter (if needed)
|
||||
count++;
|
||||
if (count == 1024) count = 0;
|
||||
}
|
86
build/shared/dist/examples/serial_comm/serialCom_strings/serialCom_strings.pde
vendored
Normal file
86
build/shared/dist/examples/serial_comm/serialCom_strings/serialCom_strings.pde
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
/* ------------------------------------------------
|
||||
* SERIAL COM - HANDELING MULTIPLE BYTES inside ARDUINO - 04_function development
|
||||
* by beltran berrocal
|
||||
*
|
||||
* this prog establishes a connection with the pc and waits for it to send him
|
||||
* a long string of characters like "hello Arduino!".
|
||||
* Then Arduino informs the pc that it heard the whole sentence
|
||||
*
|
||||
* the same as examlpe 03 but it deploys 2 reusable functions.
|
||||
* for doing the same job.
|
||||
* readSerialString() and printSerialString()
|
||||
* you just need to instantiate an array that will hold all the chars of the string
|
||||
* I've put a 100 value for excess, but if you exactly know how many bytes you are expecting
|
||||
* simply write it down inside the brackets [yourLengthHere]
|
||||
*
|
||||
* created 16 Decembre 2005;
|
||||
* copyleft 2005 Progetto25zero1 <http://www.progetto25zero1.com>
|
||||
*
|
||||
* --------------------------------------------------- */
|
||||
|
||||
char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
|
||||
// -> you must state how long the array will be else it won't work properly
|
||||
|
||||
//read a string from the serial and store it in an array
|
||||
//you must supply the array variable
|
||||
void readSerialString (char *strArray) {
|
||||
int i = 0;
|
||||
if(Serial.available()) {
|
||||
Serial.print("reading Serial String: "); //optional: for confirmation
|
||||
while (serialAvailable()){
|
||||
strArray[i] = Serial.read();
|
||||
i++;
|
||||
Serial.write(strArray[(i-1)]); //optional: for confirmation
|
||||
}
|
||||
Serial.println(); //optional: for confirmation
|
||||
}
|
||||
}
|
||||
|
||||
//Print the whole string at once - will be performed only if thers is data inside it
|
||||
//you must supply the array variable
|
||||
void printSerialString(char *strArray) {
|
||||
int i=0;
|
||||
if (strArray[i] != 0) {
|
||||
while(strArray[i] != 0) {
|
||||
Serial.print( strArray[i] );
|
||||
strArray[i] = 0; // optional: flush the content
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//utility function to know wither an array is empty or not
|
||||
boolean isStringEmpty(char *strArray) {
|
||||
if (strArray[0] == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop () {
|
||||
//simple feedback from Arduino
|
||||
Serial.println("Hello World");
|
||||
|
||||
//read the serial port and create a string out of what you read
|
||||
readSerialString(serInString);
|
||||
|
||||
//do somenthing else perhaps wait for other data or read another Serial string
|
||||
Serial.println("------------ arduino is doing somenthing else ");
|
||||
|
||||
|
||||
if( isStringEmpty(serInString) == false) { //this check is optional
|
||||
Serial.println("Arduino recorded that you said: ");
|
||||
//try to print out collected information. it will do it only if there actually is some info.
|
||||
printSerialString(serInString);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
//slows down the visualization in the terminal
|
||||
delay(2000);
|
||||
}
|
43
build/shared/dist/examples/serial_comm/serial_read_advanced/serial_read_advanced.pde
vendored
Normal file
43
build/shared/dist/examples/serial_comm/serial_read_advanced/serial_read_advanced.pde
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/* Serial Read Advanced
|
||||
* --------------------
|
||||
*
|
||||
* turns on and off a light emitting diode(LED) connected to digital
|
||||
* pin 13. The LED will light up when receiving a 'H' over the serial
|
||||
* port. The LED will blink shortly.
|
||||
*
|
||||
* Created 1 December 2005
|
||||
* copyleft 2005 DojoDave <http://www.0j0.org>
|
||||
* http://arduino.berlios.de
|
||||
*
|
||||
*/
|
||||
|
||||
int ledPin = 13; // select the pin for the LED
|
||||
int val = 0; // variable to store the data from the serial port
|
||||
int serbyte = 0; // variable to store the VALID data from the port
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin,OUTPUT); // declare the LED's pin as output
|
||||
Serial.begin(9600); // connect to the serial port
|
||||
}
|
||||
|
||||
void loop () {
|
||||
// read the serial port
|
||||
serbyte = Serial.read();
|
||||
|
||||
// if the input is '-1' then there is no data
|
||||
// at the input, otherwise store it
|
||||
if (val != -1) {
|
||||
val = serbyte;
|
||||
}
|
||||
|
||||
// if the stored value is 'H' turn the LED on
|
||||
if (val == 'H') {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
} else {
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
|
||||
delay(200);
|
||||
|
||||
}
|
||||
|
35
build/shared/dist/examples/serial_comm/serial_read_basic/serial_read_basic.pde
vendored
Normal file
35
build/shared/dist/examples/serial_comm/serial_read_basic/serial_read_basic.pde
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
/* Serial Read Basic
|
||||
* -----------------
|
||||
*
|
||||
* turns on and off a light emitting diode(LED) connected to digital
|
||||
* pin 13. The LED will light up when receiving a 'H' over the serial
|
||||
* port. The LED will blink shortly.
|
||||
*
|
||||
* Created 1 December 2005
|
||||
* copyleft 2005 DojoDave <http://www.0j0.org>
|
||||
* http://arduino.berlios.de
|
||||
*
|
||||
*/
|
||||
|
||||
int ledPin = 13; // select the pin for the LED
|
||||
int val = 0; // variable to store the data from the serial port
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin,OUTPUT); // declare the LED's pin as output
|
||||
Serial.begin(9600); // connect to the serial port
|
||||
}
|
||||
|
||||
void loop () {
|
||||
// read the serial port
|
||||
val = Serial.read();
|
||||
|
||||
// if the input is '-1' then there is no data
|
||||
// at the input, otherwise check out if it is 'H'
|
||||
if (val != -1) {
|
||||
if (val == 'H') {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
delay(200);
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
}
|
||||
}
|
40
build/shared/dist/examples/serial_comm/serial_write_basic/serial_write_basic.pde
vendored
Normal file
40
build/shared/dist/examples/serial_comm/serial_write_basic/serial_write_basic.pde
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/* Serial Write Basic
|
||||
* ------------------
|
||||
*
|
||||
* turns on and off a light emitting diode(LED) connected to digital
|
||||
* pin 13. The LED will light up when pressing a button. At the same
|
||||
* time, Arduino will send two different strings over the serial
|
||||
* port depending if the button is pressed or released.
|
||||
*
|
||||
* Created 1 December 2005
|
||||
* copyleft 2005 DojoDave <http://www.0j0.org>
|
||||
* http://arduino.berlios.de
|
||||
*
|
||||
*/
|
||||
|
||||
int ledPin = 13; // select the pin for the LED
|
||||
int buttonPin = 2; // select the pin for the button
|
||||
int val = 0; // variable to store the data from the serial port
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin,OUTPUT); // declare the LED's pin as output
|
||||
pinMode(buttonPin, INPUT); // delcare the button pin as input
|
||||
Serial.begin(9600); // connect to the serial port
|
||||
}
|
||||
|
||||
void loop () {
|
||||
// read the button and store the value
|
||||
val = digitalRead(buttonPin);
|
||||
|
||||
// if the button is at HIGH, turn the LED on, off otherwise
|
||||
if (val == HIGH) {
|
||||
Serial.print("HIGH");
|
||||
digitalWrite(ledPin, HIGH);
|
||||
} else {
|
||||
Serial.print("LOW");
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
delay(1000); // convenient to use delays when sending stuff back to the comp.
|
||||
}
|
Reference in New Issue
Block a user