mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Merge branch 'master' into new-extension
This commit is contained in:
@ -0,0 +1,85 @@
|
||||
/*
|
||||
Character analysis operators
|
||||
|
||||
Examples using the character analysis operators.
|
||||
Send any byte and the sketch will tell you about it.
|
||||
|
||||
created 29 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications:
|
||||
Serial.begin(9600);
|
||||
|
||||
// send an intro:
|
||||
Serial.println("send any byte and I'll tell you everything I can about it");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// get any incoming bytes:
|
||||
if (Serial.available() > 0) {
|
||||
int thisChar = Serial.read();
|
||||
|
||||
// say what was sent:
|
||||
Serial.print("You sent me: \'");
|
||||
Serial.write(thisChar);
|
||||
Serial.print("\' ASCII Value: ");
|
||||
Serial.println(thisChar);
|
||||
|
||||
// analyze what was sent:
|
||||
if(isAlphaNumeric(thisChar)) {
|
||||
Serial.println("it's alphanumeric");
|
||||
}
|
||||
if(isAlpha(thisChar)) {
|
||||
Serial.println("it's alphabetic");
|
||||
}
|
||||
if(isAscii(thisChar)) {
|
||||
Serial.println("it's ASCII");
|
||||
}
|
||||
if(isWhitespace(thisChar)) {
|
||||
Serial.println("it's whitespace");
|
||||
}
|
||||
if(isControl(thisChar)) {
|
||||
Serial.println("it's a control character");
|
||||
}
|
||||
if(isDigit(thisChar)) {
|
||||
Serial.println("it's a numeric digit");
|
||||
}
|
||||
if(isGraph(thisChar)) {
|
||||
Serial.println("it's a printable character that's not whitespace");
|
||||
}
|
||||
if(isLowerCase(thisChar)) {
|
||||
Serial.println("it's lower case");
|
||||
}
|
||||
if(isPrintable(thisChar)) {
|
||||
Serial.println("it's printable");
|
||||
}
|
||||
if(isPunct(thisChar)) {
|
||||
Serial.println("it's punctuation");
|
||||
}
|
||||
if(isSpace(thisChar)) {
|
||||
Serial.println("it's a space character");
|
||||
}
|
||||
if(isUpperCase(thisChar)) {
|
||||
Serial.println("it's upper case");
|
||||
}
|
||||
if (isHexadecimalDigit(thisChar)) {
|
||||
Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)");
|
||||
}
|
||||
|
||||
// add some space and ask for another byte:
|
||||
Serial.println();
|
||||
Serial.println("Give me another byte:");
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
47
build/shared/examples/8.Strings/StringToInt/StringToInt.pde
Normal file
47
build/shared/examples/8.Strings/StringToInt/StringToInt.pde
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
String to Integer conversion
|
||||
|
||||
Reads a serial input string until it sees a newline, then converts
|
||||
the string to a number if the characters are digits.
|
||||
|
||||
The circuit:
|
||||
No external components needed.
|
||||
|
||||
created 29 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
String inString = ""; // string to hold input
|
||||
|
||||
void setup() {
|
||||
// Initialize serial communications:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Read serial input:
|
||||
while (Serial.available() > 0) {
|
||||
int inChar = Serial.read();
|
||||
if (isDigit(inChar)) {
|
||||
// convert the incoming byte to a char
|
||||
// and add it to the string:
|
||||
inString += (char)inChar;
|
||||
}
|
||||
// if you get a newline, print the string,
|
||||
// then the string's value:
|
||||
if (inChar == '\n') {
|
||||
Serial.print("Value:");
|
||||
Serial.println(inString.toInt());
|
||||
Serial.print("String: ");
|
||||
Serial.println(inString);
|
||||
// clear the string for new input:
|
||||
inString = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,230 @@
|
||||
/*
|
||||
Serial RGB controller
|
||||
|
||||
Reads a serial input string looking for three comma-separated
|
||||
integers with a newline at the end. Values should be between
|
||||
0 and 255. The sketch uses those values to set the color
|
||||
of an RGB LED attached to pins 9 - 11.
|
||||
|
||||
The circuit:
|
||||
* Common-anode RGB LED cathodes attached to pins 9 - 11
|
||||
* LED anode connected to pin 13
|
||||
|
||||
To turn on any given channel, set the pin LOW.
|
||||
To turn off, set the pin HIGH. The higher the analogWrite level,
|
||||
the lower the brightness.
|
||||
|
||||
created 29 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
String inString = ""; // string to hold input
|
||||
int currentColor = 0;
|
||||
int red, green, blue = 0;
|
||||
|
||||
void setup() {
|
||||
// Initialize serial communications:
|
||||
Serial.begin(9600);
|
||||
// set LED cathode pins as outputs:
|
||||
pinMode(9, OUTPUT);
|
||||
pinMode(10, OUTPUT);
|
||||
pinMode(11, OUTPUT);
|
||||
// turn on pin 13 to power the LEDs:
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, HIGH);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int inChar;
|
||||
|
||||
// Read serial input:
|
||||
if (Serial.available() > 0) {
|
||||
inChar = Serial.read();
|
||||
}
|
||||
|
||||
if (isDigit(inChar)) {
|
||||
// convert the incoming byte to a char
|
||||
// and add it to the string:
|
||||
inString += (char)inChar;
|
||||
}
|
||||
|
||||
// if you get a comma, convert to a number,
|
||||
// set the appropriate color, and increment
|
||||
// the color counter:
|
||||
if (inChar == ',') {
|
||||
// do something different for each value of currentColor:
|
||||
switch (currentColor) {
|
||||
case 0: // 0 = red
|
||||
red = inString.toInt();
|
||||
// clear the string for new input:
|
||||
inString = "";
|
||||
break;
|
||||
case 1: // 1 = green:
|
||||
green = inString.toInt();
|
||||
// clear the string for new input:
|
||||
inString = "";
|
||||
break;
|
||||
}
|
||||
currentColor++;
|
||||
}
|
||||
// if you get a newline, you know you've got
|
||||
// the last color, i.e. blue:
|
||||
if (inChar == '\n') {
|
||||
blue = inString.toInt();
|
||||
|
||||
// set the levels of the LED.
|
||||
// subtract value from 255 because a higher
|
||||
// analogWrite level means a dimmer LED, since
|
||||
// you're raising the level on the anode:
|
||||
analogWrite(11, 255 - red);
|
||||
analogWrite(9, 255 - green);
|
||||
analogWrite(10, 255 - blue);
|
||||
|
||||
// print the colors:
|
||||
Serial.print("Red: ");
|
||||
Serial.print(red);
|
||||
Serial.print(", Green: ");
|
||||
Serial.print(green);
|
||||
Serial.print(", Blue: ");
|
||||
Serial.println(blue);
|
||||
|
||||
// clear the string for new input:
|
||||
inString = "";
|
||||
// reset the color counter:
|
||||
currentColor = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Here's a Processing sketch that will draw a color wheel and send a serial
|
||||
string with the color you click on:
|
||||
|
||||
// Subtractive Color Wheel with Serial
|
||||
// Based on a Processing example by Ira Greenberg.
|
||||
// Serial output added by Tom Igoe
|
||||
//
|
||||
// The primaries are red, yellow, and blue. The secondaries are green,
|
||||
// purple, and orange. The tertiaries are yellow-orange, red-orange,
|
||||
// red-purple, blue-purple, blue-green, and yellow-green.
|
||||
//
|
||||
// Create a shade or tint of the subtractive color wheel using
|
||||
// SHADE or TINT parameters.
|
||||
|
||||
// Updated 29 November 2010.
|
||||
|
||||
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
int segs = 12;
|
||||
int steps = 6;
|
||||
float rotAdjust = TWO_PI / segs / 2;
|
||||
float radius;
|
||||
float segWidth;
|
||||
float interval = TWO_PI / segs;
|
||||
|
||||
Serial myPort;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
background(127);
|
||||
smooth();
|
||||
ellipseMode(RADIUS);
|
||||
noStroke();
|
||||
// make the diameter 90% of the sketch area
|
||||
radius = min(width, height) * 0.45;
|
||||
segWidth = radius / steps;
|
||||
|
||||
// swap which line is commented out to draw the other version
|
||||
// drawTintWheel();
|
||||
drawShadeWheel();
|
||||
// open the first serial port in your computer's list
|
||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||
}
|
||||
|
||||
|
||||
void drawShadeWheel() {
|
||||
for (int j = 0; j < steps; j++) {
|
||||
color[] cols = {
|
||||
color(255-(255/steps)*j, 255-(255/steps)*j, 0),
|
||||
color(255-(255/steps)*j, (255/1.5)-((255/1.5)/steps)*j, 0),
|
||||
color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0),
|
||||
color(255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j, 0),
|
||||
color(255-(255/steps)*j, 0, 0),
|
||||
color(255-(255/steps)*j, 0, (255/2)-((255/2)/steps)*j),
|
||||
color(255-(255/steps)*j, 0, 255-(255/steps)*j),
|
||||
color((255/2)-((255/2)/steps)*j, 0, 255-(255/steps)*j),
|
||||
color(0, 0, 255-(255/steps)*j),
|
||||
color(0, 255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j),
|
||||
color(0, 255-(255/steps)*j, 0),
|
||||
color((255/2)-((255/2)/steps)*j, 255-(255/steps)*j, 0)
|
||||
};
|
||||
for (int i = 0; i < segs; i++) {
|
||||
fill(cols[i]);
|
||||
arc(width/2, height/2, radius, radius,
|
||||
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
|
||||
}
|
||||
radius -= segWidth;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawTintWheel() {
|
||||
for (int j = 0; j < steps; j++) {
|
||||
color[] cols = {
|
||||
color((255/steps)*j, (255/steps)*j, 0),
|
||||
color((255/steps)*j, ((255/1.5)/steps)*j, 0),
|
||||
color((255/steps)*j, ((255/2)/steps)*j, 0),
|
||||
color((255/steps)*j, ((255/2.5)/steps)*j, 0),
|
||||
color((255/steps)*j, 0, 0),
|
||||
color((255/steps)*j, 0, ((255/2)/steps)*j),
|
||||
color((255/steps)*j, 0, (255/steps)*j),
|
||||
color(((255/2)/steps)*j, 0, (255/steps)*j),
|
||||
color(0, 0, (255/steps)*j),
|
||||
color(0, (255/steps)*j, ((255/2.5)/steps)*j),
|
||||
color(0, (255/steps)*j, 0),
|
||||
color(((255/2)/steps)*j, (255/steps)*j, 0)
|
||||
};
|
||||
for (int i = 0; i < segs; i++) {
|
||||
fill(cols[i]);
|
||||
arc(width/2, height/2, radius, radius,
|
||||
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
|
||||
}
|
||||
radius -= segWidth;
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// nothing happens here
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
// get the color of the mouse position's pixel:
|
||||
color targetColor = get(mouseX, mouseY);
|
||||
// get the component values:
|
||||
int r = int(red(targetColor));
|
||||
int g = int(green(targetColor));
|
||||
int b = int(blue(targetColor));
|
||||
// make a comma-separated string:
|
||||
String colorString = r + "," + g + "," + b + "\n";
|
||||
// send it out the serial port:
|
||||
myPort.write(colorString );
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,3 +1,65 @@
|
||||
ARDUINO 0022
|
||||
|
||||
[core / libraries]
|
||||
|
||||
* Adding an SD card library based on sdfatlib by Bill Greiman and the
|
||||
MemoryCard library by Philip Lindsay (follower) for SparkFun.
|
||||
http://arduino.cc/en/Reference/SD
|
||||
|
||||
* Added character manipulation macros (from Wiring): isAlphaNumeric(),
|
||||
isAlpha(), isAscii(), isWhitespace(), isControl(), isDigit(), isGraph(),
|
||||
isLowerCase(), isPrintable(), isPunct(), isSpace(), isUpperCase(),
|
||||
isHexadecimalDigit(), toAscii(), toLowerCase(), toLowerCase().
|
||||
http://code.google.com/p/arduino/issues/detail?id=418
|
||||
|
||||
* Added String.toInt() function.
|
||||
|
||||
* Refactoring core to use register-based, not CPU-based, #ifdefs.
|
||||
Patch by Mark Sproul.
|
||||
http://code.google.com/p/arduino/issues/detail?id=307
|
||||
http://code.google.com/p/arduino/issues/detail?id=315
|
||||
http://code.google.com/p/arduino/issues/detail?id=316
|
||||
http://code.google.com/p/arduino/issues/detail?id=323
|
||||
http://code.google.com/p/arduino/issues/detail?id=324
|
||||
http://code.google.com/p/arduino/issues/detail?id=340
|
||||
|
||||
* Modification of serial baud rate calculation to match bootloader and 8U2
|
||||
firmware at 57600 baud.
|
||||
http://code.google.com/p/arduino/issues/detail?id=394
|
||||
|
||||
* Fixed bug in tone() function.
|
||||
http://code.google.com/p/arduino/issues/detail?id=361
|
||||
|
||||
* Fixed SPI.setClockDivider() function.
|
||||
http://code.google.com/p/arduino/issues/detail?id=365
|
||||
|
||||
* Hardware serial receive interrupt optimization.
|
||||
http://code.google.com/p/arduino/issues/detail?id=391
|
||||
|
||||
* Applying the timeout parameter of pulseIn() during measurement of the
|
||||
pulse, not just while waiting for it.
|
||||
|
||||
[environment]
|
||||
|
||||
* Fixed problem with copy as html and angle brackets.
|
||||
http://code.google.com/p/arduino/issues/detail?id=29
|
||||
|
||||
* Showing serial port selection dialog if serial port not found on upload.
|
||||
|
||||
* Remembering serial monitor window size and line ending selection.
|
||||
http://code.google.com/p/arduino/issues/detail?id=96
|
||||
http://code.google.com/p/arduino/issues/detail?id=330
|
||||
|
||||
* Replaced oro.jar regular expressions with java.regex ones (patch by
|
||||
Eberhard Fahle and Christian Maglie).
|
||||
http://code.google.com/p/arduino/issues/detail?id=171
|
||||
|
||||
* Building the user sketch before the core or libraries, so errors appear
|
||||
faster. Patch by William Westfield and Paul Stoffregen.
|
||||
http://code.google.com/p/arduino/issues/detail?id=393
|
||||
|
||||
* Setting application icon under Windows.
|
||||
|
||||
ARDUINO 0021 - 2010.10.02
|
||||
|
||||
* Modifying VID / PID combination in 8U2 firmwares.
|
||||
|
Reference in New Issue
Block a user