ENIB 2023 : La byby
Révision datée du 15 janvier 2024 à 17:00 par Antonydbzh (discussion | contributions) (→Catégories)
La fabuleuse équipe
Le principe du projet
C'est un labyrinthe, une bille doit partir d'un coin du plateau pour arriver à un autre coin. Le joueur doit incliner le plateau sur deux axes à laide de potentiomètres sur le côté du labyby
Liste des composants
- Carte arduino Micro
- 14 fils
- 2 servos
- 2 potentiomètres
- une boite adaptée
Code
#include <Servo.h>
Servo myservo1;
Servo myservo2;// create servo object to control a servo
int potpin1 = A0;
int potpin2 = A1;// analog pin used to connect the potentiometer
int val1;
int val2;// variable to read the value from the analog pin
void setup() {
myservo1.attach(9);
myservo2.attach(8);// attaches the servo on pin 9 to the servo object
}
void loop() {
val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 180 );
Serial.println(val1);
val2 = analogRead(potpin2);
val2 = map(val2, 0, 1023, 0, 180);
Serial.println(val2);// scale it for use with the servo (value between 0 and 180)
myservo1.write(val1);
myservo2.write(val2);// sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
