mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-23 19:21:59 +03:00
First integration of the Arduino code in Processing 5503: PreProcessor and Compiler have been integrated with changes to the Sketch.
Compilation still has problems (Thread error on success, and can't handle non-pde files in a sketch). Modified the Mac OS X make.sh to copy the hardware, avr tools, and example over. Removing some of the antlr stuff. Disabling the Commander (command-line execution) for now. Added Library, LibraryManager, and Target. Added support for prefixed preferences (e.g. for boards and programmers).
This commit is contained in:
47
build/shared/examples/Sensors/ADXL3xx/ADXL3xx.pde
Normal file
47
build/shared/examples/Sensors/ADXL3xx/ADXL3xx.pde
Normal file
@ -0,0 +1,47 @@
|
||||
// ADXL3xx
|
||||
//
|
||||
// Reads an Analog Devices ADXL3xx accelerometer and communicates the
|
||||
// acceleration to the computer. The pins used are designed to be easily
|
||||
// compatible with the breakout boards from Sparkfun, available from:
|
||||
// http://www.sparkfun.com/commerce/categories.php?c=80
|
||||
//
|
||||
// http://www.arduino.cc/en/Tutorial/ADXL3xx
|
||||
|
||||
// Breakout Board Pinout
|
||||
// 0: self test
|
||||
// 1: z-axis
|
||||
// 2: y-axis
|
||||
// 3: x-axis
|
||||
// 4: ground
|
||||
// 5: vcc
|
||||
|
||||
int groundpin = 18; // analog input pin 4
|
||||
int powerpin = 19; // analog input pin 5
|
||||
int xpin = 3; // x-axis of the accelerometer
|
||||
int ypin = 2; // y-axis
|
||||
int zpin = 1; // z-axis (only on 3-axis models)
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// Provide ground and power by using the analog inputs as normal
|
||||
// digital pins. This makes it possible to directly connect the
|
||||
// breakout board to the Arduino. If you use the normal 5V and
|
||||
// GND pins on the Arduino, you can remove these lines.
|
||||
pinMode(groundpin, OUTPUT);
|
||||
pinMode(powerpin, OUTPUT);
|
||||
digitalWrite(groundpin, LOW);
|
||||
digitalWrite(powerpin, HIGH);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(analogRead(xpin));
|
||||
Serial.print(" ");
|
||||
Serial.print(analogRead(ypin));
|
||||
Serial.print(" ");
|
||||
Serial.print(analogRead(zpin));
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
34
build/shared/examples/Sensors/Knock/Knock.pde
Normal file
34
build/shared/examples/Sensors/Knock/Knock.pde
Normal file
@ -0,0 +1,34 @@
|
||||
/* Knock Sensor
|
||||
* by DojoDave <http://www.0j0.org>
|
||||
*
|
||||
* Program using a Piezo element as if it was a knock sensor.
|
||||
*
|
||||
* We have to basically listen to an analog pin and detect
|
||||
* if the signal goes over a certain threshold. It writes
|
||||
* "knock" to the serial port if the Threshold is crossed,
|
||||
* and toggles the LED on pin 13.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Knock
|
||||
*/
|
||||
|
||||
int ledPin = 13; // led connected to control pin 13
|
||||
int knockSensor = 0; // the knock sensor will be plugged at analog pin 0
|
||||
byte val = 0; // variable to store the value read from the sensor pin
|
||||
int statePin = LOW; // variable used to store the last LED status, to toggle the light
|
||||
int THRESHOLD = 100; // threshold value to decide when the detected sound is a knock or not
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
|
||||
Serial.begin(9600); // use the serial port
|
||||
}
|
||||
|
||||
void loop() {
|
||||
val = analogRead(knockSensor); // read the sensor and store it in the variable "val"
|
||||
if (val >= THRESHOLD) {
|
||||
statePin = !statePin; // toggle the status of the ledPin (this trick doesn't use time cycles)
|
||||
digitalWrite(ledPin, statePin); // turn the led on or off
|
||||
Serial.println("Knock!"); // send the string "Knock!" back to the computer, followed by newline
|
||||
}
|
||||
delay(100); // we have to make a delay to avoid overloading the serial port
|
||||
}
|
||||
|
43
build/shared/examples/Sensors/Memsic2125/Memsic2125.pde
Normal file
43
build/shared/examples/Sensors/Memsic2125/Memsic2125.pde
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Memsic2125
|
||||
*
|
||||
* Read the Memsic 2125 two-axis accelerometer. Converts the
|
||||
* pulses output by the 2125 into milli-g's (1/1000 of earth's
|
||||
* gravity) and prints them over the serial connection to the
|
||||
* computer.
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Memsic2125
|
||||
*/
|
||||
|
||||
int xpin = 2;
|
||||
int ypin = 3;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
pinMode(xpin, INPUT);
|
||||
pinMode(ypin, INPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int pulseX, pulseY;
|
||||
int accX, accY;
|
||||
|
||||
// read pulse from x- and y-axes
|
||||
pulseX = pulseIn(xpin,HIGH);
|
||||
pulseY = pulseIn(ypin,HIGH);
|
||||
|
||||
// convert the pulse width into acceleration
|
||||
// accX and accY are in milli-g's: earth's gravity is 1000.
|
||||
accX = ((pulseX / 10) - 500) * 8;
|
||||
accY = ((pulseY / 10) - 500) * 8;
|
||||
|
||||
// print the acceleration
|
||||
Serial.print(accX);
|
||||
Serial.print(" ");
|
||||
Serial.print(accY);
|
||||
Serial.println();
|
||||
|
||||
delay(100);
|
||||
}
|
56
build/shared/examples/Sensors/Ping/Ping.pde
Normal file
56
build/shared/examples/Sensors/Ping/Ping.pde
Normal file
@ -0,0 +1,56 @@
|
||||
int pingPin = 7;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
long duration, inches, cm;
|
||||
|
||||
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
|
||||
// We give a short LOW pulse beforehand to ensure a clean HIGH pulse.
|
||||
pinMode(pingPin, OUTPUT);
|
||||
digitalWrite(pingPin, LOW);
|
||||
delayMicroseconds(2);
|
||||
digitalWrite(pingPin, HIGH);
|
||||
delayMicroseconds(5);
|
||||
digitalWrite(pingPin, LOW);
|
||||
|
||||
// The same pin is used to read the signal from the PING))): a HIGH
|
||||
// pulse whose duration is the time (in microseconds) from the sending
|
||||
// of the ping to the reception of its echo off of an object.
|
||||
pinMode(pingPin, INPUT);
|
||||
duration = pulseIn(pingPin, HIGH);
|
||||
|
||||
// convert the time into a distance
|
||||
inches = microsecondsToInches(duration);
|
||||
cm = microsecondsToCentimeters(duration);
|
||||
|
||||
Serial.print(inches);
|
||||
Serial.print("in, ");
|
||||
Serial.print(cm);
|
||||
Serial.print("cm");
|
||||
Serial.println();
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
long microsecondsToInches(long microseconds)
|
||||
{
|
||||
// According to Parallax's datasheet for the PING))), there are
|
||||
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
|
||||
// second). This gives the distance travelled by the ping, outbound
|
||||
// and return, so we divide by 2 to get the distance of the obstacle.
|
||||
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
|
||||
return microseconds / 74 / 2;
|
||||
}
|
||||
|
||||
long microsecondsToCentimeters(long microseconds)
|
||||
{
|
||||
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
|
||||
// The ping travels out and back, so to find the distance of the
|
||||
// object we take half of the distance travelled.
|
||||
return microseconds / 29 / 2;
|
||||
}
|
Reference in New Issue
Block a user