Arduino/Lauflicht mit Schalter und Potentiometer: Unterschied zwischen den Versionen

Aus ZUM-Unterrichten
main>Belofb
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Markierung: 2017-Quelltext-Bearbeitung
 
(6 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
[[Datei:Arduino-Lauflicht mit Schalter und Potentiometer.JPG|400px|links]]
[[Datei:Arduino-Lauflicht mit Schalter und Potentiometer.JPG|400px|right]]


Das [[Arduino]]-Board wurde zusammen mit zwei Steckplatinen auf einer Holzplatte befestigt, um die Handhabbarkeit für den Unterricht in der Schule zu verbessern. Für die Befestigung des Arduino-Boards auf der Platte gibt es hier einen [https://www.flickr.com/photos/johngineer/5484250200/ Bohrplan].
Das [[Arduino]]-Board wurde zusammen mit zwei Steckplatinen auf einer Holzplatte befestigt, um die Handhabbarkeit für den Unterricht in der Schule zu verbessern. Für die Befestigung des Arduino-Boards auf der Platte gibt es hier einen [https://www.flickr.com/photos/johngineer/5484250200/ Bohrplan].


Die Steuerung schaltet 3 LEDs, die als Lauflichter funktionieren. Der Taster dient dazu, das Lauflicht anzuschalten. Das Lauflicht bleibt solange an, wie der Taster gedrückt bleibt. Die Zeitdauer, die jede LED an ist, wird über ein an PIN A0 angeschlossenes Potentiometer eingestellt. Der ausgelesene Wert wird in der Variablen "potiVal".
Die Steuerung schaltet 3 LEDs, die als Lauflichter funktionieren. Der Taster dient dazu, das Lauflicht anzuschalten. Das Lauflicht bleibt solange an, wie der Taster gedrückt bleibt. Die Zeitdauer, die jede LED an ist, wird über ein am PIN A0 angeschlossenes Potentiometer eingestellt. Der ausgelesene Wert wird in der Variablen <code>potiVal</code> gespeichert.
 
{{clear}}


Sourcecode für Arduino-Sketch mit ausführlicher Kommentierung (englischsprachig)
Sourcecode für Arduino-Sketch mit ausführlicher Kommentierung (englischsprachig)
<source lang="c++">
/*
  Light chaser with pushbutton and variable speed
  Turns on and off LED1, then turns on and off LED2 and now turns on and off LED3.
  After this the procedure starts again.
  The loop routine runs only when the pushbutton switch is pressed.
  The chasing frequency can be set by the potentiometer.
  */
// Pin numbers are allocated to the variables led1, led2 and led3
// the digital input (pushbutton) and the analog input (potentiometer) are selected
// the variables for the inputs are chosen and set to 0 at the beginning of the sketch:
const int led1 = 11; //  11 (for LED Pin 11) is allocated to the variable led1
const int led2 = 12; //  12 (for LED Pin 12) is allocated to the variable led1
const int led3 = 13; //  13 (for LED Pin 13) is allocated to the variable led1
const int button = 7; // 7 (for button Pin 7) is allocated to the variable button
const int potiPin = A0; // A0 (for potentiometer Input Pin A0) is allocated to the
                          //variable potiPin
int val = 0;  // the variable to store the state of the input pin 7 (button)
                //is defined (val) and set to 0 (LOW) at the beginning of the sketch.
int potiVal = 0;  // the variable to store the value coming from analog input pin 7
                  //(potentiometer) is defined (potiVal) and is set to 0 at the
                // beginning of the sketch
// the setup routine runs once when you press reset:
void setup() {               
// initializes the digital pins 11, 12 and 13 as outputs.
pinMode(led1, OUTPUT); //led1 or pin 11 is an output
pinMode(led2, OUTPUT); //led2 or pin 12 is an output
pinMode(led3, OUTPUT); //led3 or pin 13 is an output 
}


:/*
// the loop routine runs as long as the pushbutton is pressed
:  Light chaser with pushbutton and variable speed
void loop() {
:  Turns on and off LED1, then turns on and off LED2 and now turns on and off LED3.
  {
:  After this the procedure starts again.
  val = digitalRead(button);//read input value and store it
:  The loop routine runs only when the pushbutton switch is pressed.
//check whether the input is HIGH (button)pressed
:  The chasing frequency can be set by the potentiometer.
  if (val == HIGH) {   
:  */
   
:
  potiVal = analogRead(potiPin); // read the value from the sensor                     
:// Pin numbers are allocated to the variables led1, led2 and led3
     
:// the digital input (pushbutton) and the analog input (potentiometer) are selected
  digitalWrite(led1, HIGH); // turn the LED1 on (HIGH is the voltage level)
:// the variables for the inputs are chosen and set to 0 at the beginning of the sketch
  delay(potiVal);              // wait for the time set by the Potentiometer
:
  digitalWrite(led1, LOW);  // switch LED1 off by setting the voltage to LOW
:const int led1 = 11; //  11 (for LED Pin 11) is allocated to the variable led1
 
:const int led2 = 12; //  12 (for LED Pin 12) is allocated to the variable led1
  digitalWrite(led2, HIGH); // turn the LED2 on by setting the voltage to HIGH
:const int led3 = 13; //  13 (for LED Pin 13) is allocated to the variable led1
  delay(potiVal);              // wait for the time set by the Potentiometer
:const int button = 7; // 7 (for button Pin 7) is allocated to the variable button
  digitalWrite(led2, LOW);  //switch LED2 off by setting the voltage to LOW
:const int potiPin = A0; // A0 (for potentiometer Input Pin A0) is allocated to the
 
:                          //variable potiPin
  digitalWrite(led3, HIGH); // turn the LED3 on by setting the voltage to HIGH
:
  delay(potiVal);              // wait for the time set by the Potentiometer
:int val = 0;  // the variable to store the state of the input pin 7 (button)
  digitalWrite(led3, LOW);  // switch LED3 off by setting the voltage to LOW
:                //is defined (val) and set to 0 (LOW) at the beginning of the sketch.
  }
:int potiVal = 0;  // the variable to store the value coming from analog input pin 7
  else {     
:                  //(potentiometer) is defined (potiVal) and is set to 0 at the
  digitalWrite(led1, LOW);  // switch LED1 off by setting the voltage to LOW              
:                // beginning of the sketch
  digitalWrite(led2, LOW);  //switch LED2 off by setting the voltage to LOW  
:
  digitalWrite(led3, LOW);  // switch LED3 off by setting the voltage to LOW  
:// the setup routine runs once when you press reset:
   }
:
}}
:void setup() {               
</source>
:  // initializes the digital pins 11, 12 and 13 as outputs.
:  pinMode(led1, OUTPUT); //led1 or pin 11 is an output
:  pinMode(led2, OUTPUT); //led2 or pin 12 is an output
:  pinMode(led3, OUTPUT); //led3 or pin 13 is an output 
:}
:
:// the loop routine runs as long as the pushbutton is pressed
:void loop() {
: {
: val = digitalRead(button);//read input value and store it
//check whether the input is HIGH (button)pressed
if (val == HIGH) {   
:   
potiVal = analogRead(potiPin); // read the value from the sensor                     
:     
digitalWrite(led1, HIGH); // turn the LED1 on (HIGH is the voltage level)
delay(potiVal);              // wait for a second
digitalWrite(led1, LOW);  // switch LED1 off by setting the voltage to LOW
digitalWrite(led2, HIGH); // turn the LED2 on by setting the voltage to HIGH
: delay(potiVal);              // wait for a second
: digitalWrite(led2, LOW);  //switch LED2 off by setting the voltage to LOW
digitalWrite(led3, HIGH); // turn the LED3 on by setting the voltage to HIGH
delay(potiVal);              // wait for a second
digitalWrite(led3, LOW);  // switch LED3 off by setting the voltage to LOW
: } else {
:    
: digitalWrite(led1, LOW);  // switch LED1 off by setting the voltage to LOW
:               
: digitalWrite(led2, LOW);  //switch LED2 off by setting the voltage to LOW
:   
: digitalWrite(led3, LOW);  // switch LED3 off by setting the voltage to LOW
:   }
:}}


{{SORTIERUNG:{{SUBPAGENAME}}}}
{{SORTIERUNG:{{SUBPAGENAME}}}}
[[Kategorie:Arduino]]
{{Arduino-Projekt}}

Aktuelle Version vom 15. Februar 2020, 14:12 Uhr

Arduino-Lauflicht mit Schalter und Potentiometer.JPG

Das Arduino-Board wurde zusammen mit zwei Steckplatinen auf einer Holzplatte befestigt, um die Handhabbarkeit für den Unterricht in der Schule zu verbessern. Für die Befestigung des Arduino-Boards auf der Platte gibt es hier einen Bohrplan.

Die Steuerung schaltet 3 LEDs, die als Lauflichter funktionieren. Der Taster dient dazu, das Lauflicht anzuschalten. Das Lauflicht bleibt solange an, wie der Taster gedrückt bleibt. Die Zeitdauer, die jede LED an ist, wird über ein am PIN A0 angeschlossenes Potentiometer eingestellt. Der ausgelesene Wert wird in der Variablen potiVal gespeichert.



Sourcecode für Arduino-Sketch mit ausführlicher Kommentierung (englischsprachig)

/*
  Light chaser with pushbutton and variable speed
  Turns on and off LED1, then turns on and off LED2 and now turns on and off LED3. 
  After this the procedure starts again. 
  The loop routine runs only when the pushbutton switch is pressed.
  The chasing frequency can be set by the potentiometer.
   */
 
// Pin numbers are allocated to the variables led1, led2 and led3
// the digital input (pushbutton) and the analog input (potentiometer) are selected
// the variables for the inputs are chosen and set to 0 at the beginning of the sketch:
const int led1 = 11; //  11 (for LED Pin 11) is allocated to the variable led1
const int led2 = 12; //  12 (for LED Pin 12) is allocated to the variable led1
const int led3 = 13; //  13 (for LED Pin 13) is allocated to the variable led1
const int button = 7; // 7 (for button Pin 7) is allocated to the variable button
const int potiPin = A0; // A0 (for potentiometer Input Pin A0) is allocated to the
                          //variable potiPin

int val = 0;   // the variable to store the state of the input pin 7 (button)
                //is defined (val) and set to 0 (LOW) at the beginning of the sketch.
int potiVal = 0;  // the variable to store the value coming from analog input pin 7 
                  //(potentiometer) is defined (potiVal) and is set to 0 at the
                 // beginning of the sketch

// the setup routine runs once when you press reset:

void setup() {                
// initializes the digital pins 11, 12 and 13 as outputs.
pinMode(led1, OUTPUT); //led1 or pin 11 is an output
pinMode(led2, OUTPUT); //led2 or pin 12 is an output
pinMode(led3, OUTPUT); //led3 or pin 13 is an output  
}

// the loop routine runs as long as the pushbutton is pressed
void loop() {
 {
 val = digitalRead(button);//read input value and store it
//check whether the input is HIGH (button)pressed
  if (val == HIGH) {  
    
  potiVal = analogRead(potiPin); // read the value from the sensor                    
      
  digitalWrite(led1, HIGH); // turn the LED1 on (HIGH is the voltage level)
  delay(potiVal);              // wait for the time set by the Potentiometer
  digitalWrite(led1, LOW);  // switch LED1 off by setting the voltage to LOW
  
  digitalWrite(led2, HIGH); // turn the LED2 on by setting the voltage to HIGH
 delay(potiVal);              // wait for the time set by the Potentiometer
 digitalWrite(led2, LOW);  //switch LED2 off by setting the voltage to LOW
  
  digitalWrite(led3, HIGH); // turn the LED3 on by setting the voltage to HIGH
  delay(potiVal);              // wait for the time set by the Potentiometer
  digitalWrite(led3, LOW);  // switch LED3 off by setting the voltage to LOW  
  } 
 else {    
 digitalWrite(led1, LOW);  // switch LED1 off by setting the voltage to LOW               
 digitalWrite(led2, LOW);  //switch LED2 off by setting the voltage to LOW   
 digitalWrite(led3, LOW);  // switch LED3 off by setting the voltage to LOW 
   }
}}


Arduino Logo.svg

Arduino-Projekt

  1. Lauflicht mit Schalter und Potentiometer, um die Anschaltdauer der Dioden einzustellen
  2. Datenvisualisierung mit Processing
  3. Datenvisualisierung mit einem Oszilloskop
  4. Ansteuerung von Pneumatikventilen mit dem Arduino
  5. Steuerung einer Lampe, die angeht, wenn bei Dunkelheit eine Person den Parkplatz betritt