Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
projets:turntable:accueil [2019/03/21 11:26] resonance créée |
projets:turntable:accueil [2019/04/24 13:35] (Version actuelle) resonance [Turntable] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | {{: | ||
+ | |||
====== Turntable ====== | ====== Turntable ====== | ||
+ | |||
* Porteur du projet : resonance | * Porteur du projet : resonance | ||
* Date : 12/02/2019 | * Date : 12/02/2019 | ||
* Licence : libre ! | * Licence : libre ! | ||
- | * Contexte | + | * Fichiers Scratch |
- | * Fichiers : {{ : | + | * Fichiers |
+ | * | ||
+ | |||
+ | |||
+ | ===== Test ===== | ||
+ | |||
+ | | {{youtube> | ||
+ | === code arduino | ||
+ | ++++ audio-scratchBtn2.ino | | ||
+ | <code cpp> | ||
+ | / | ||
+ | Two phase quadrature encoder(Incremental) | ||
+ | * **************************************************** | ||
+ | To determine motor with encode (CW OR CCW) | ||
+ | |||
+ | @author Dong | ||
+ | @version | ||
+ | @date 2016-5-26 | ||
+ | All above must be included in any redistribution | ||
+ | * ****************************************************/ | ||
+ | # | ||
+ | # | ||
+ | double flag_A = 0; //Assign a value to the token bit | ||
+ | double flag_B = 0; //Assign a value to the token bit | ||
+ | double pos = 0; | ||
+ | double newpos = 0; | ||
+ | |||
+ | /** * */ | ||
+ | |||
+ | // set pin numbers: | ||
+ | const int buttonPin = 8; // the number of the pushbutton pin | ||
+ | const int ledPin = 13; // the number of the LED pin | ||
+ | // variables will change: | ||
+ | int buttonState = 0; // variable for reading the pushbutton status | ||
+ | int previousButtonState = 0; | ||
+ | |||
+ | |||
+ | void setup() { | ||
+ | // initialize the LED pin as an output: | ||
+ | pinMode(ledPin, | ||
+ | // initialize the pushbutton pin as an input: | ||
+ | pinMode(buttonPin, | ||
+ | // | ||
+ | pinMode(A_PHASE, | ||
+ | pinMode(B_PHASE, | ||
+ | Serial.begin(9600); | ||
+ | //Interrupt trigger mode: RISING | ||
+ | attachInterrupt(digitalPinToInterrupt( A_PHASE), interrupt, RISING); | ||
+ | previousButtonState = digitalRead(buttonPin); | ||
+ | } | ||
+ | void loop() { | ||
+ | |||
+ | if (pos != newpos){ | ||
+ | Serial.print(" | ||
+ | Serial.println(pos); | ||
+ | delay(10);// | ||
+ | newpos = pos; | ||
+ | | ||
+ | |||
+ | // | ||
+ | // read the state of the pushbutton value: | ||
+ | buttonState = digitalRead(buttonPin); | ||
+ | // check if the pushbutton is pressed. | ||
+ | // if it is, the buttonState is HIGH: | ||
+ | if (buttonState == HIGH && previousButtonState == LOW) { | ||
+ | // turn LED on: | ||
+ | digitalWrite(ledPin, | ||
+ | Serial.println(" | ||
+ | delay(20); | ||
+ | } | ||
+ | if (buttonState == LOW && previousButtonState == HIGH) { | ||
+ | // turn LED off: | ||
+ | digitalWrite(ledPin, | ||
+ | Serial.println(" | ||
+ | delay(20); | ||
+ | } | ||
+ | previousButtonState = buttonState; | ||
- | ===== Principe ===== | + | } |
- | Utilisation d'un [[https:// | + | void interrupt()// Interrupt function |
- | {{youtube> | + | { char i; |
+ | i = digitalRead( B_PHASE); | ||
+ | if (i == 1) | ||
+ | | ||
+ | flag_A += 1; | ||
+ | } | ||
+ | else | ||
+ | | ||
+ | flag_B += 1; | ||
+ | | ||
+ | pos = flag_A - flag_B; | ||
+ | } | ||
+ | </ | ||
+ | ++++ |