1
0
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:
Federico Fissore
2013-10-21 09:58:40 +02:00
parent 3c6ee46828
commit b4c68b3dff
259 changed files with 5160 additions and 5217 deletions

View File

@ -1,21 +1,21 @@
/* Robot Inputs
This sketch shows you how to use the on-board
potentiometer and buttons as inputs.
This sketch shows you how to use the on-board
potentiometer and buttons as inputs.
Turning the potentiometer draws a clock-shaped
circle. The up and down buttons change the pitch,
while the left and right buttons change the tempo.
Turning the potentiometer draws a clock-shaped
circle. The up and down buttons change the pitch,
while the left and right buttons change the tempo.
The middle button resets tempo and pitch.
Circuit:
* Arduino Robot
created 1 May 2013
by X. Yang
modified 12 May 2013
by D. Cuartielles
This example is in the public domain
*/
@ -26,16 +26,16 @@ int tempo = 60;
int pitch = 1000;
void setup() {
// initialize the Robot, SD card, speaker, and display
// initialize the Robot, SD card, speaker, and display
Robot.begin();
Robot.beginTFT();
Robot.beginSpeaker();
Robot.beginSD();
// draw "lg0.bmp" and "lg1.bmp" on the screen
// draw "lg0.bmp" and "lg1.bmp" on the screen
Robot.displayLogos();
// play a sound file
// play a sound file
Robot.playFile("Melody.sqm");
}
@ -50,55 +50,55 @@ void loop() {
// Draw the basic interface
void renderUI() {
//fill the buttons blank
Robot.fill(255, 255, 255);
Robot.fill(255, 255, 255);
Robot.rect(53, 58, 13, 13); // left
Robot.rect(93, 58, 13, 13); // right
Robot.rect(73, 38, 13, 13); // up
Robot.circle(79, 64, 6); // middle
Robot.rect(73, 78, 13, 13); // down
//draw the knob
Robot.noFill();
Robot.circle(26, 116, 17); // knob
//draw the vertical bargraph
int fullPart=map(pitch, 200, 2000, 0, 58); //length of filled bargraph
Robot.fill(255, 255, 255);
Robot.rect(21, 30, 13, 58-fullPart);
Robot.fill(0, 0, 255);
Robot.rect(21, 88-fullPart, 13, fullPart); //58-fullPart+30
int fullPart = map(pitch, 200, 2000, 0, 58); //length of filled bargraph
Robot.fill(255, 255, 255);
Robot.rect(21, 30, 13, 58 - fullPart);
Robot.fill(0, 0, 255);
Robot.rect(21, 88 - fullPart, 13, fullPart); //58-fullPart+30
//draw the horizontal bargraph
fullPart = map(tempo, 20, 100, 0, 58); // length of filled bargraph
Robot.fill(255, 190, 0);
Robot.fill(255, 190, 0);
Robot.rect(53, 110, fullPart, 13);
Robot.fill(255, 255, 255);
Robot.rect(53+fullPart, 110, 58-fullPart, 13);
Robot.fill(255, 255, 255);
Robot.rect(53 + fullPart, 110, 58 - fullPart, 13);
}
void keyDown(int keyCode) {
// use a static int so it is persistent over time
static int oldKey;
switch(keyCode) {
switch (keyCode) {
case BUTTON_LEFT:
//left button pressed, reduces tempo
tempo -= 5;
if(tempo < 20) tempo = 20; //lowest tempo 20
Robot.fill(255,190,0);
if (tempo < 20) tempo = 20; //lowest tempo 20
Robot.fill(255, 190, 0);
Robot.rect(53, 58, 13, 13);
break;
case BUTTON_RIGHT:
//right button pressed, increases tempo
tempo += 5;
if(tempo > 100) tempo = 100; //highest tempo 100
Robot.fill(255,190,0);
if (tempo > 100) tempo = 100; //highest tempo 100
Robot.fill(255, 190, 0);
Robot.rect(93, 58, 13, 13);
break;
case BUTTON_UP:
//up button pressed, increases pitch
pitch += 120;
if(pitch > 2000) pitch = 2000;
if (pitch > 2000) pitch = 2000;
Robot.fill(0, 0, 255);
Robot.rect(73, 38, 13, 13);
@ -106,8 +106,8 @@ void keyDown(int keyCode) {
case BUTTON_DOWN:
//down button pressed, reduces pitch
pitch -= 120;
if(pitch < 200){
pitch = 200;
if (pitch < 200) {
pitch = 200;
}
Robot.fill(0, 0, 255);
@ -117,49 +117,49 @@ void keyDown(int keyCode) {
//middle button pressed, resets tempo and pitch
tempo = 60;
pitch = 1000;
Robot.fill(160,160,160);
Robot.fill(160, 160, 160);
Robot.circle(79, 64, 6);
break;
case BUTTON_NONE:
//Only when the keys are released(thus BUTTON_NONE is
//encountered the first time), the interface will be
//encountered the first time), the interface will be
//re-drawn.
if(oldKey != BUTTON_NONE){
if (oldKey != BUTTON_NONE) {
renderUI();
}
break;
}
if(oldKey != keyCode) {
if (oldKey != keyCode) {
// change the song's tempo
Robot.tempoWrite(tempo);
// change the song's pitch
Robot.tuneWrite(float(pitch/1000.0));
Robot.tuneWrite(float(pitch / 1000.0));
}
oldKey = keyCode;
}
//Draw a circle according to value
//of the knob.
//of the knob.
void drawKnob(int val) {
static int val_old;
int r=map(val,0,1023,1,15);
//Only updates when the
int r = map(val, 0, 1023, 1, 15);
//Only updates when the
//value changes.
if(val_old!=r){
if (val_old != r) {
Robot.noFill();
//erase the old circle
Robot.stroke(255, 255, 255);
Robot.circle(26,116,r+1);
Robot.circle(26, 116, r + 1);
//draw the new circle
Robot.stroke(255, 0, 255);
Robot.circle(26,116,r);
Robot.circle(26, 116, r);
Robot.stroke(0, 0, 0);
val_old=r;
val_old = r;
}
}