ArduCitrouille : Différence entre versions
De Nybi.cc
(→Exemple) |
(→Exemple) |
||
Ligne 8 : | Ligne 8 : | ||
== Exemple == | == Exemple == | ||
+ | Voir la vidéo complète : [http://wiki.nybi.cc/images/4/41/Ardu-citrouille.ogv ardu-citrouillev0] | ||
+ | |||
+ | En image fixe : [[media:Image-010.jpg]] | ||
+ | |||
+ | Extrait : | ||
[[Fichier:Ardu-citrouille.gif]] | [[Fichier:Ardu-citrouille.gif]] | ||
− | |||
− | |||
− | |||
== Programme == | == Programme == |
Version actuelle en date du 15 mai 2015 à 13:58
Introduction
Inspiration : Peter, the cyber pumpkin.
Exemple
Voir la vidéo complète : ardu-citrouillev0
En image fixe : media:Image-010.jpg
Programme
// Controlling a servo position using a potentiometer (variable resistor) // by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> #include <Servo.h> #include <stdarg.h> void debug(char *fmt, ... ){ char tmp[128]; // resulting string limited to 128 chars va_list args; va_start (args, fmt ); vsnprintf(tmp, 128, fmt, args); va_end (args); Serial.print(tmp); } Servo myservo; // create servo object to control a servo int debattement = 35; int target_pos = 90; int current_pos = target_pos - debattement; int delta_pos = 5; void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object pinMode(10, OUTPUT); pinMode(11, OUTPUT); Serial.begin(9600); Serial.println("Hello world"); delay(2000);// Give reader a chance to see the output. } void loop() { current_pos = current_pos + delta_pos; if (current_pos >= target_pos) { target_pos = 90 - debattement; } if (current_pos < target_pos) { target_pos = 90 + debattement; } delta_pos = (target_pos > current_pos) ? 1 : -1; if (delta_pos > 0) { digitalWrite(10, LOW); digitalWrite(11, HIGH); } else { digitalWrite(10, HIGH); digitalWrite(11, LOW); } debug("%d looking at %d by step %d\n", current_pos, target_pos, delta_pos); myservo.write(current_pos); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there }