Élaboration du programme sous Proteus
|
III - Élaboration du programme directement sous Proteus 8 en langage C/C++ style IDE Arduino
Le schéma structurel à utiliser
Arduino_BL_feux_tri_v1.pdsprj
Le code source à compléter
/* Main.ino file generated by New Project wizard * Created: 9 novembre 2022 * Processor: ATmega328P * Compiler: Arduino AVR */
int ledR1Pin = 2; // LED Rouge feux1 connected to digital pin 2 int ledR2Pin = 5; // LED Rouge feux2 connected to digital pin 5 int ledO1Pin = 3; // LED Orange feux1 connected to digital pin 3 int ledO2Pin = 6; // LED Orange feux2 connected to digital pin 6 int ledV1Pin = 4; // LED Verte feux1 connected to digital pin 4 int ledV2Pin = 7; // LED Verte feux2 connected to digital pin 7 int inPin = 8; // push-button connected to digital pin 8 --> Mode Jour/nuit (IO8 = PB0) int mode = 0; // variable to store the read value // mode:variable pour stocker la valeur lue du Mode void Mode_Nuit() { digitalWrite(ledR1Pin, LOW); // turn the LED off by making the voltage LOW digitalWrite(ledR2Pin, LOW); // turn the LED off digitalWrite(ledV1Pin, LOW); // turn the LED off digitalWrite(ledV2Pin, LOW); // turn the LED off digitalWrite(ledO1Pin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(ledO2Pin, HIGH); // turn the LED on delay(300); // wait for 300 ms
digitalWrite(ledO1Pin, LOW); // turn the LED off digitalWrite(ledO2Pin, LOW); // turn the LED off delay(200); // wait for 200 ms }
void Mode_Jour() // à compléter { digitalWrite(ledR1Pin, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(ledR2Pin, HIGH); // turn the LED on digitalWrite(ledO1Pin, LOW); // turn the LED off by making the voltage LOW digitalWrite(ledO2Pin, LOW); // turn the LED off // à compléter }
void setup() { // put your setup code here, to run once: pinMode(ledR1Pin, OUTPUT); // initialize digital pin as an output. pinMode(ledR2Pin, OUTPUT); // initialize digital pin as an output. pinMode(ledO1Pin, OUTPUT); // initialize digital pin as an output. pinMode(ledO2Pin, OUTPUT); // initialize digital pin as an output. pinMode(ledV1Pin, OUTPUT); // initialize digital pin as an output. pinMode(ledV2Pin, OUTPUT); // initialize digital pin as an output. pinMode(inPin, INPUT); // sets the digital pin 8 as an input pin 8 --> Mode Jour/nuit }
void loop() { // programme principal (loop) mode=digitalRead(inPin); // read the input pin 8 (IO8 = PB0) // lire la broche d'entrée pin 8 if(mode==0) // si la valeur de mode est à 0 { Mode_Nuit(); // alors Mode_Nuit } else { Mode_Jour(); // sinon Mode_Jour } }
|
Copyright © samedi 7 janvier 2023 à 16:15:27 by blewando.elec@gmail.com
Créé avec HelpNDoc Personal Edition: Documentation Qt Help facile