Étape 3: Programmation de l’Arduino
Partie du code de notre projet :
const int buttonPin = 11 ;
const int motorPin = 12 ;
const int ledPin = 10 ;
int potPin = A0 ;
int potValue = 0 ;
int motorValue = 0 ;
void setup() {pinMode (buttonPin, entrée) ;
pinMode (motorPin, sortie) ;
pinMode (ledPin, sortie) ;
Serial.Begin(9600) ; }
void loop() {int buttonState ;
buttonState = digitalRead(buttonPin) ;
potValue = analogRead(potPin) ;
motorValue = carte (potValue, 0, 1023, 0, 255) ;
analogWrite (motorPin, motorValue) ;
Serial.Print ("potentiomètre =") ;
Serial.Print(potValue) ;
Serial.Print ("\t moteur =") ;
Serial.println(motorValue) ;
Delay(2) ;
if(ButtonState == Low) {digitalWrite (motorPin, HIGH) ;
digitalWrite (ledPin, HIGH) ;
} else {digitalWrite (motorPin, basse) ;
digitalWrite (ledPin, basse) ;
} }