Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.
projets:conception_d_un_robot_a_base_d_arduino [2018/02/18 15:39] thierry_dasse |
projets:conception_d_un_robot_a_base_d_arduino [2018/02/18 15:45] (Version actuelle) thierry_dasse |
||
---|---|---|---|
Ligne 68: | Ligne 68: | ||
+ | Fichier tactilservo.cpp à insérer dans le répertoire Arduino/librairies/TactilServo | ||
+ | |||
+ | Pendant la séance du 17 février, nous n'avons pas eu le temps d'implémenter toutes les méthodes. Il nous faudra finir. | ||
+ | |||
+ | <code c++> | ||
+ | |||
+ | #include "tactilservo.h" | ||
+ | |||
+ | void TactilServo::init(int servoPin, int switchPin) { | ||
+ | this->servoPin = servoPin; | ||
+ | this->switchPin = switchPin; | ||
+ | this->openPos = 180; | ||
+ | this->closePos = 0; | ||
+ | this->angleDelay = 15; | ||
+ | this->attach(this->servoPin); | ||
+ | pinMode(this->switchPin,INPUT); | ||
+ | digitalWrite(this->switchPin,HIGH); | ||
+ | } | ||
+ | |||
+ | void TactilServo::setOpenPos(int pos) { | ||
+ | // A faire | ||
+ | } | ||
+ | |||
+ | void TactilServo::setClosePos(int pos) { | ||
+ | // A faire | ||
+ | } | ||
+ | |||
+ | void TactilServo::setAngleSpeed(int s) { | ||
+ | // A faire | ||
+ | } | ||
+ | |||
+ | void TactilServo::open() { | ||
+ | this->write(this->openPos); | ||
+ | } | ||
+ | |||
+ | int TactilServo::close() { | ||
+ | int pos = this->read(); | ||
+ | while ((digitalRead(this->switchPin) != 0) && (pos > this->closePos)) { | ||
+ | pos -= 1; | ||
+ | this->write(pos); | ||
+ | delay(this->angleDelay); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | Programme de test testpince.ino | ||
+ | |||
+ | <code c++> | ||
+ | #include "tactilservo.h" | ||
+ | |||
+ | TactilServo mapince; | ||
+ | |||
+ | void setup() { | ||
+ | mapince.init(3,2); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | mapince.open(); | ||
+ | delay(2000); | ||
+ | mapince.close(); //si on appuie sur le poussoir, la pince s'arrête | ||
+ | delay(5000); | ||
+ | } | ||
+ | |||
+ | </code> | ||