mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Adding debounce example; adding Max/MSP code to the communication examples.
This commit is contained in:
parent
91f22e2d96
commit
ca84925df8
@ -72,3 +72,20 @@ void draw()
|
||||
port.write(mouseX);
|
||||
}
|
||||
*/
|
||||
|
||||
/* Max/MSP patch for this example
|
||||
|
||||
max v2;
|
||||
#N vpatcher 10 59 610 459;
|
||||
#P user uslider 286 66 18 128 255 1 0 0;
|
||||
#P window setfont "Sans Serif" 9.;
|
||||
#P window linecount 1;
|
||||
#P message 212 192 32 196617 print;
|
||||
#P newex 286 217 71 196617 serial a 9600;
|
||||
#P window linecount 2;
|
||||
#P comment 316 148 100 196617 Slide the fader to dim the LED;
|
||||
#P comment 69 192 125 196617 Click here to get a list of serial ports;
|
||||
#P fasten 4 0 2 0 291 215 291 215;
|
||||
#P fasten 3 0 2 0 217 212 291 212;
|
||||
#P pop;
|
||||
*/
|
||||
|
@ -103,3 +103,55 @@ void serialEvent(int serial)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/* Max/MSP patch for this example
|
||||
|
||||
#P user multiSlider 285 285 246 167 0. 1023. 1 3433 47 0 0 2 0 0 0;
|
||||
#M frgb 17 15 198;
|
||||
#M brgb 59 182 255;
|
||||
#M rgb2 127 127 127;
|
||||
#M rgb3 0 0 0;
|
||||
#M rgb4 37 52 91;
|
||||
#M rgb5 74 105 182;
|
||||
#M rgb6 112 158 18;
|
||||
#M rgb7 149 211 110;
|
||||
#M rgb8 187 9 201;
|
||||
#M rgb9 224 62 37;
|
||||
#M rgb10 7 114 128;
|
||||
#P window setfont "Sans Serif" 9.;
|
||||
#P window linecount 1;
|
||||
#P comment 300 110 191 196617 Click here to get a list of serial ports;
|
||||
#P window linecount 2;
|
||||
#P comment 166 265 112 196617 Here's the number from Arduino's analog input;
|
||||
#P window linecount 1;
|
||||
#P comment 353 243 215 196617 Convert ASCII to symbol;
|
||||
#P comment 353 220 215 196617 Convert integer to ASCII;
|
||||
#P number 285 264 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
|
||||
#P newex 285 243 62 196617 fromsymbol;
|
||||
#B color 5;
|
||||
#P newex 285 220 40 196617 itoa;
|
||||
#B color 5;
|
||||
#P newex 285 197 55 196617 zl group 4;
|
||||
#P newex 229 159 67 196617 select 10 13;
|
||||
#P toggle 229 66 15 0;
|
||||
#P newex 229 88 52 196617 metro 10;
|
||||
#P message 264 110 32 196617 print;
|
||||
#P newex 229 135 71 196617 serial a 9600;
|
||||
#P window linecount 2;
|
||||
#P comment 34 88 191 196617 Read serial input buffer every 10 milliseconds;
|
||||
#P window linecount 3;
|
||||
#P comment 302 159 215 196617 If you get newline (ASCII 10) \, send the list. If you get return (ASCII 13) do nothing. Any other value \, add to the list;
|
||||
#P window linecount 1;
|
||||
#P comment 256 66 100 196617 Click to start;
|
||||
#P connect 6 0 5 0;
|
||||
#P connect 5 0 3 0;
|
||||
#P connect 11 0 16 0;
|
||||
#P connect 10 0 11 0;
|
||||
#P connect 9 0 10 0;
|
||||
#P connect 8 0 9 0;
|
||||
#P fasten 7 0 8 0 234 188 290 188;
|
||||
#P fasten 7 2 8 0 290 200 290 200;
|
||||
#P connect 3 0 7 0;
|
||||
#P fasten 4 0 3 0 269 130 234 130;
|
||||
#P window clipboard copycount 17;
|
||||
*/
|
||||
|
@ -88,3 +88,33 @@ void draw()
|
||||
rect(50, 50, 100, 100); // draw square
|
||||
}
|
||||
*/
|
||||
|
||||
/* Max/MSP patch for this example.
|
||||
|
||||
max v2;
|
||||
#N vpatcher 140 160 740 560;
|
||||
#P window setfont "Sans Serif" 9.;
|
||||
#P window linecount 1;
|
||||
#P comment 333 191 100 196617 Converts to integer;
|
||||
#P window linecount 2;
|
||||
#P comment 333 127 100 196617 bangs H for on \, L for off;
|
||||
#P window linecount 1;
|
||||
#P newex 263 127 41 196617 sel 1 0;
|
||||
#P toggle 263 54 60 0;
|
||||
#P message 278 151 14 196617 L;
|
||||
#P newex 263 191 40 196617 atoi;
|
||||
#P message 263 151 14 196617 H;
|
||||
#P message 224 191 32 196617 print;
|
||||
#P newex 263 217 71 196617 serial a 9600;
|
||||
#P window linecount 2;
|
||||
#P comment 333 75 100 196617 Click here to turn on or off the LED;
|
||||
#P comment 121 191 98 196617 Click to get a list of the serial ports;
|
||||
#P connect 7 0 8 0;
|
||||
#P connect 8 0 4 0;
|
||||
#P fasten 4 0 5 0 268 178 268 178;
|
||||
#P fasten 6 0 5 0 283 178 268 178;
|
||||
#P fasten 3 0 2 0 229 212 268 212;
|
||||
#P fasten 5 0 2 0 268 212 268 212;
|
||||
#P connect 8 1 6 0;
|
||||
#P pop;
|
||||
*/
|
||||
|
@ -87,3 +87,184 @@ void serialEvent(int serial)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/* Max/MSP patch for this example
|
||||
|
||||
max v2;
|
||||
#N vpatcher 0 44 587 638;
|
||||
#P window setfont "Sans Serif" 9.;
|
||||
#P comment 137 34 100 196617 Read the serial port every two milliseconds;
|
||||
#P window linecount 1;
|
||||
#P newex 156 276 27 196617 / 4;
|
||||
#P number 156 254 35 9 0 1023 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
|
||||
#P newex 106 276 27 196617 / 4;
|
||||
#P number 106 254 35 9 0 1023 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
|
||||
#P newex 55 276 27 196617 / 4;
|
||||
#P number 55 254 35 9 0 1023 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
|
||||
#P hidden newex 55 303 112 196617 bgcolor 220 120 192;
|
||||
#P user multiSlider 167 145 125 91 0. 1023. 1 3449 15 0 0 2 0 0 0;
|
||||
#M frgb 0 0 0;
|
||||
#M brgb 255 255 255;
|
||||
#M rgb2 127 127 127;
|
||||
#M rgb3 0 0 0;
|
||||
#M rgb4 37 52 91;
|
||||
#M rgb5 74 105 182;
|
||||
#M rgb6 112 158 18;
|
||||
#M rgb7 149 211 110;
|
||||
#M rgb8 187 9 201;
|
||||
#M rgb9 224 62 37;
|
||||
#M rgb10 7 114 128;
|
||||
#P user multiSlider 438 145 125 91 0. 1023. 1 3449 15 0 0 2 0 0 0;
|
||||
#M frgb 0 0 0;
|
||||
#M brgb 255 255 255;
|
||||
#M rgb2 127 127 127;
|
||||
#M rgb3 0 0 0;
|
||||
#M rgb4 37 52 91;
|
||||
#M rgb5 74 105 182;
|
||||
#M rgb6 112 158 18;
|
||||
#M rgb7 149 211 110;
|
||||
#M rgb8 187 9 201;
|
||||
#M rgb9 224 62 37;
|
||||
#M rgb10 7 114 128;
|
||||
#P user multiSlider 301 144 125 91 0. 1023. 1 3449 15 0 0 2 0 0 0;
|
||||
#M frgb 0 0 0;
|
||||
#M brgb 255 255 255;
|
||||
#M rgb2 127 127 127;
|
||||
#M rgb3 0 0 0;
|
||||
#M rgb4 37 52 91;
|
||||
#M rgb5 74 105 182;
|
||||
#M rgb6 112 158 18;
|
||||
#M rgb7 149 211 110;
|
||||
#M rgb8 187 9 201;
|
||||
#M rgb9 224 62 37;
|
||||
#M rgb10 7 114 128;
|
||||
#N vpatcher 20 74 303 387;
|
||||
#P window setfont "Sans Serif" 9.;
|
||||
#P newex 92 248 62 196617 fromsymbol;
|
||||
#B color 5;
|
||||
#P message 134 231 73 196617
|
||||
;
|
||||
#P newex 134 211 62 196617 prepend set;
|
||||
#B color 5;
|
||||
#P newex 92 211 40 196617 itoa;
|
||||
#B color 5;
|
||||
#P newex 92 191 55 196617 zl group 4;
|
||||
#P newex 50 158 52 196617 select 10;
|
||||
#P message 130 86 14 196617 1;
|
||||
#P message 112 86 14 196617 0;
|
||||
#P newex 50 132 27 196617 gate;
|
||||
#P newex 130 64 52 196617 select 82;
|
||||
#P comment 151 45 25 196617 "R";
|
||||
#P inlet 130 44 15 0;
|
||||
#P outlet 92 270 15 0;
|
||||
#P fasten 5 0 4 0 117 111 55 111;
|
||||
#P fasten 6 0 4 0 135 111 55 111;
|
||||
#P connect 4 0 7 0;
|
||||
#P fasten 3 1 4 1 177 128 72 128;
|
||||
#P connect 7 0 8 0;
|
||||
#P connect 7 1 8 0;
|
||||
#P connect 8 0 9 0;
|
||||
#P connect 9 0 12 0;
|
||||
#P connect 12 0 0 0;
|
||||
#P connect 7 0 5 0;
|
||||
#P connect 1 0 3 0;
|
||||
#P connect 3 0 6 0;
|
||||
#P connect 9 0 10 0;
|
||||
#P connect 10 0 11 0;
|
||||
#P pop;
|
||||
#P newobj 55 96 49 196617 p parseR;
|
||||
#N vpatcher 20 74 620 474;
|
||||
#P window setfont "Sans Serif" 9.;
|
||||
#P newex 92 250 62 196617 fromsymbol;
|
||||
#B color 5;
|
||||
#P message 134 233 73 196617 501
|
||||
;
|
||||
#P newex 134 213 62 196617 prepend set;
|
||||
#B color 5;
|
||||
#P newex 92 213 40 196617 itoa;
|
||||
#B color 5;
|
||||
#P newex 92 193 55 196617 zl group 4;
|
||||
#P newex 50 160 52 196617 select 10;
|
||||
#P message 130 88 14 196617 1;
|
||||
#P message 112 88 14 196617 0;
|
||||
#P newex 50 134 27 196617 gate;
|
||||
#P newex 130 66 52 196617 select 66;
|
||||
#P comment 169 50 25 196617 "B";
|
||||
#P inlet 130 46 15 0;
|
||||
#P outlet 92 272 15 0;
|
||||
#P fasten 5 0 4 0 117 113 55 113;
|
||||
#P fasten 6 0 4 0 135 113 55 113;
|
||||
#P connect 4 0 7 0;
|
||||
#P fasten 3 1 4 1 177 130 72 130;
|
||||
#P connect 7 0 8 0;
|
||||
#P connect 7 1 8 0;
|
||||
#P connect 8 0 9 0;
|
||||
#P connect 9 0 12 0;
|
||||
#P connect 12 0 0 0;
|
||||
#P connect 7 0 5 0;
|
||||
#P connect 1 0 3 0;
|
||||
#P connect 3 0 6 0;
|
||||
#P connect 9 0 10 0;
|
||||
#P connect 10 0 11 0;
|
||||
#P pop;
|
||||
#P newobj 156 96 49 196617 p parseB;
|
||||
#N vpatcher 589 252 861 563;
|
||||
#P window setfont "Sans Serif" 9.;
|
||||
#P comment 153 47 25 196617 "G";
|
||||
#P newex 92 250 62 196617 fromsymbol;
|
||||
#B color 5;
|
||||
#P message 134 233 73 196617 718
|
||||
;
|
||||
#P newex 134 213 62 196617 prepend set;
|
||||
#B color 5;
|
||||
#P newex 92 213 40 196617 itoa;
|
||||
#B color 5;
|
||||
#P newex 92 193 55 196617 zl group 4;
|
||||
#P newex 50 160 52 196617 select 10;
|
||||
#P message 130 88 14 196617 1;
|
||||
#P message 112 88 14 196617 0;
|
||||
#P newex 50 134 27 196617 gate;
|
||||
#P newex 130 66 52 196617 select 71;
|
||||
#P inlet 130 46 15 0;
|
||||
#P outlet 92 272 15 0;
|
||||
#P fasten 5 0 3 0 135 113 55 113;
|
||||
#P fasten 4 0 3 0 117 113 55 113;
|
||||
#P connect 3 0 6 0;
|
||||
#P fasten 2 1 3 1 177 130 72 130;
|
||||
#P connect 6 0 7 0;
|
||||
#P connect 6 1 7 0;
|
||||
#P connect 7 0 8 0;
|
||||
#P connect 8 0 11 0;
|
||||
#P connect 11 0 0 0;
|
||||
#P connect 6 0 4 0;
|
||||
#P connect 1 0 2 0;
|
||||
#P connect 2 0 5 0;
|
||||
#P connect 8 0 9 0;
|
||||
#P connect 9 0 10 0;
|
||||
#P pop;
|
||||
#P newobj 106 96 49 196617 p parseG;
|
||||
#P toggle 55 34 15 0;
|
||||
#P hidden newex 55 52 46 196617 metro 2;
|
||||
#P newex 55 72 71 196617 serial a 9600;
|
||||
#B color 5;
|
||||
#P window linecount 3;
|
||||
#P comment 319 50 100 196617 Virtual Color Fader Most of the code by Jamie Allen;
|
||||
#P connect 3 0 2 0;
|
||||
#P connect 2 0 1 0;
|
||||
#P connect 1 0 6 0;
|
||||
#P connect 6 0 11 0;
|
||||
#P connect 11 0 12 0;
|
||||
#P fasten 12 0 10 0 60 298 60 298;
|
||||
#P fasten 1 0 4 0 60 92 111 92;
|
||||
#P fasten 4 0 13 0 111 243 111 243;
|
||||
#P connect 13 0 14 0;
|
||||
#P connect 14 0 10 1;
|
||||
#P fasten 1 0 5 0 60 92 161 92;
|
||||
#P fasten 5 0 15 0 161 243 161 243;
|
||||
#P connect 15 0 16 0;
|
||||
#P fasten 16 0 10 2 161 298 162 298;
|
||||
#P fasten 6 0 9 0 60 129 172 129;
|
||||
#P fasten 4 0 7 0 111 129 306 129;
|
||||
#P fasten 5 0 8 0 161 129 443 129;
|
||||
#P pop;
|
||||
*/
|
||||
|
52
build/shared/dist/examples/Digital/Debounce/Debounce.pde
vendored
Normal file
52
build/shared/dist/examples/Digital/Debounce/Debounce.pde
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/* Debounce
|
||||
*
|
||||
* Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
|
||||
* press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
|
||||
* a minimum delay between toggles to debounce the circuit (i.e. to ignore
|
||||
* noise).
|
||||
*
|
||||
* David A. Mellis
|
||||
* 21 November 2006
|
||||
*
|
||||
* http://www.arduino.cc/en/Tutorial/Debounce
|
||||
*/
|
||||
|
||||
int inPin = 7; // the number of the input pin
|
||||
int outPin = 13; // the number of the output pin
|
||||
|
||||
int state = HIGH; // the current state of the output pin
|
||||
int reading; // the current reading from the input pin
|
||||
int previous = LOW; // the previous reading from the input pin
|
||||
|
||||
// the follow variables are long's because the time, measured in miliseconds,
|
||||
// will quickly become a bigger number than can be stored in an int.
|
||||
long time = 0; // the last time the output pin was toggled
|
||||
long debounce = 200; // the debounce time, increase if the output flickers
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(inPin, INPUT);
|
||||
pinMode(outPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
reading = digitalRead(inPin);
|
||||
|
||||
// if we just pressed the button (i.e. the input went from LOW to HIGH),
|
||||
// and we've waited long enough since the last press to ignore any noise...
|
||||
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
|
||||
// ... invert the output
|
||||
if (state == HIGH)
|
||||
state = LOW;
|
||||
else
|
||||
state = HIGH;
|
||||
|
||||
// ... and remember when the last button press was
|
||||
time = millis();
|
||||
}
|
||||
|
||||
digitalWrite(outPin, state);
|
||||
|
||||
previous = reading;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user