Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the Uno and
by Scott Fitzgerald
*/
// the setup function runs once when you press reset or power the board
void setup() {
pinMode(13, OUTPUT);
void loop() {
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
}
/*
Fade
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
http://www.arduino.cc/en/Tutorial/Button
*/
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
Plays a melody
circuit:
* 8-ohm speaker on digital pin 8
http://www.arduino.cc/en/Tutorial/Tone
*/
#include "pitches.h"
void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
void loop() {
// no need to repeat the melody.
}
/* for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
Arrays // turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
Demonstrates the use of an array to hold pin numbers delay(timer);
in order to iterate over the pins in a sequence. // turn the pin off:
Lights multiple LEDs in sequence, then in reverse. digitalWrite(ledPins[thisPin], LOW);
}
Unlike the For Loop tutorial, where the pins have to be }
contiguous, here the pins can be in any random order.
The circuit:
* LEDs from pins 2 through 7 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
http://www.arduino.cc/en/Tutorial/Array
*/
void setup() {
// the array elements are numbered from 0 to (pinCount -
1).
// use a for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}
void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
// variables:
int sensorValue = 0; // the sensor value
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
void setup() {
// turn on LED to signal the start of the calibration period:
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
The circuit:
* LEDs attached from pins 2 through 13 to ground.
*/
// These constants won't change. They're used to give
names
// to the pins used:
const int lowestPin = 2;
const int highestPin = 13;
void setup() {
// set pins 2 through 13 as outputs:
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++)
{
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// iterate over the pins:
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++)
{
// fade the LED on thisPin from off to brightest:
for (int brightness = 0; brightness < 255; brightness++) {
analogWrite(thisPin, brightness);
delay(2);
}
// fade the LED on thisPin from brithstest to off:
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(thisPin, brightness);
delay(2);
}
// pause between LEDs:
delay(100);
}
}
/* // turn LED on:
Button digitalWrite(ledPin, HIGH);
} else {
Turns on and off a light emitting diode(LED) connected to // turn LED off:
digital digitalWrite(ledPin, LOW);
pin 13, when pressing a pushbutton attached to pin 2. }
}
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
http://www.arduino.cc/en/Tutorial/Button
*/
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
Demonstrates the use a 16x2 LCD display. The LiquidCrystal void loop() {
library works with all LCD displays that are compatible with // set the cursor to column 0, line 1
the // (note: line 1 is the second row, since counting begins
Hitachi HD44780 driver. There are many of them out there, with 0):
and you lcd.setCursor(2, 1);
can usually tell them by the 16-pin interface. // print the number of seconds since reset:
lcd.print("HEHE");
This sketch prints "Hello Marlon!" to the LCD
and shows the time.
}
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
void setup(){
pinMode(soundSensorPin, INPUT);
for(int i=0; i<numberOfPins;i++){
pinMode(LEDPins[i],OUTPUT);
}
}
void loop(){
soundReading=analogRead(soundSensorPin);
if(soundReading>soundThreshold){
if(switcher){
aboveThreshold(currentPin);
switcher=true;
}
} else {
if(switcher){
belowThreshold();
switcher=true;
}
}
}
if(currentPin==numberOfPins){
currentPin=0;
}
}
void belowThreshold(){
switcher=false;
fadeCounter++;
if(fadeCounter==fadeDelay){
fadeCounter=0;
for(int i=0; i<numberOfPins;i++){
int ledpin1 = 13; digitalWrite(7,LOW);
int ledpin2 = 12; delay(10);
int ledpin3 = 11; digitalWrite(6,LOW);
int ledpin4 = 10; delay(100);
int ledpin5 = 9;
int ledpin6 = 8; }
int ledpin7 = 7;
int ledpin8 = 6;
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13,HIGH);
delay(10);
digitalWrite(12,HIGH);
delay(100);
digitalWrite(11,HIGH);
delay(10);
digitalWrite(10,HIGH);
delay(100);
digitalWrite(9,HIGH);
delay(10);
digitalWrite(8,HIGH);
delay(100);
digitalWrite(7,HIGH);
delay(10);
digitalWrite(6,HIGH);
delay(100);
digitalWrite(13,LOW);
delay(10);
digitalWrite(12,LOW);
delay(100);
digitalWrite(11,LOW);
delay(10);
digitalWrite(10,LOW);
delay(100);
digitalWrite(9,LOW);
delay(10);
digitalWrite(8,LOW);
delay(100);