Lezione 2
LEZIONE n° 2 – SENSORI
La lezione è sui sensori e sulla loro gestione. I primi sensori che saranno gestiti sono i LED.
Per provare a fare le modifiche proposte copiare il listato (colorato in rosso) ed incollarlo in un editor di solo testo [Notepad ad esempio]
listato programma esempio numero 1:
/* Blink
Turns on and off a light emitting diode(LED) connected to a digital pin.
The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that’s attached to pin 13, so no hardware is needed for this example.
*/
Turns on and off a light emitting diode(LED) connected to a digital pin.
The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that’s attached to pin 13, so no hardware is needed for this example.
*/
// set pin numbers:
const int ledPin = 13; // the number of the LED pin
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
int ledState = LOW; // ledState used to set the LED
void setup() {
pinMode(ledPin, OUTPUT); // set the digital pin as output:
}
pinMode(ledPin, OUTPUT); // set the digital pin as output:
}
void loop() // here is where you’d put code that needs to be running all the time.
{ // 1000 egual 1 seconds
unsigned long tempo = 250;
{ // 1000 egual 1 seconds
unsigned long tempo = 250;
digitalWrite(ledPin, HIGH);
delay(tempo);
delay(tempo);
digitalWrite(ledPin, LOW);
delay(tempo);
}
delay(tempo);
}
listato programma esempio numero 2:
/* Blink
Turns on and off a light emitting diode(LED) connected to a digital pin.
The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that’s attached to pin 13, so no hardware is needed for this example.
*/
Turns on and off a light emitting diode(LED) connected to a digital pin.
The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that’s attached to pin 13, so no hardware is needed for this example.
*/
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
int buttonState = 0; // variable for reading the pushbutton status
int ledState = LOW; // ledState used to set the LED
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
pinMode(ledPin, OUTPUT); // set the digital pin as output:
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input:
}
pinMode(ledPin, OUTPUT); // set the digital pin as output:
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input:
}
void loop() // here is where you’d put code that needs to be running all the time.
{ // 1000 egual 1 seconds
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) { // check if the pushbutton is pressed.
// turn LED on:
digitalWrite(ledPin, HIGH); // if it is, the buttonState is HIGH:
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
{ // 1000 egual 1 seconds
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) { // check if the pushbutton is pressed.
// turn LED on:
digitalWrite(ledPin, HIGH); // if it is, the buttonState is HIGH:
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
di seguito le slide della lezione
lezione2_001lezione2_022lezione2_002lezione2_023lezione2_003lezione2_004lezione2_024lezione2_005lezione2_025lezione2_006lezione2_007lezione2_008lezione2_009lezione2_010lezione2_011lezione2_012lezione2_013lezione2_014lezione2_015lezione2_016lezione2_017lezione2_018lezione2_019lezione2_020lezione2_021
(62)
Articolo in Evidenza
Le categorie
- .Dicono di NOI
- Album fotografici Francesco
- Album Fotografici Iduesarchiaponi
- Album Fotografici Paolo
- Alta Fotografia
- Altro
- Antichi eserciti ed armi
- Archeologia
- Archeologia1
- Archeologia2
- Archivio Robotica
- Circuiti per Robotica
- Città Fantasma
- Collaboratori
- Corso Robotica 19-20
- Didattica
- Didattica a distanza
- Esempi di Robotica
- Eventi
- Fotografia
- Francesco
- Francesco e Paolo
- Gallerie Fotografiche Francesco
- Gare di Robotica
- Gli Svaghi nel mondo Antico
- I Cibi Romani
- Il blog
- L'Italia che non ti aspetti
- Laboratorio Robotica
- Le sette Meraviglie del mondo
- Le Sette meraviglie del Mondo moderne
- Lezioni On-line
- Link Utili
- Miti e Leggende
- Mitologia Norena
- Notizie
- Paolo
- Per non dimenticare
- Popoli e Civiltà
- Robotica
- Roma Nascosta
- Scrittori e Poeti Antichi
- Scuola
- Si dice… Perchè
- Soluzioni didattica a distanza
- Storie e Personaggi Romani
- Teatro
- Viaggiando …..
- Viaggiare
- Video