start:arduino:74hc595:programmes
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| start:arduino:74hc595:programmes [2022/03/08 11:04] – gerardadmin | start:arduino:74hc595:programmes [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 3: | Ligne 3: | ||
| [[https:// | [[https:// | ||
| + | |||
| + | |||
| Ligne 8: | Ligne 10: | ||
| La bibliothèque Arduino ShiftRegister74HC595 simplifie l' | La bibliothèque Arduino ShiftRegister74HC595 simplifie l' | ||
| - | ccode c > | + | < |
| - | sr.set(2, HIGH); | + | sr.set(2, HIGH);// mettre à 1 la sortie |
| </ | </ | ||
| Ligne 65: | Ligne 67: | ||
| sr.updateRegisters(); | sr.updateRegisters(); | ||
| } | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Programmation d un 74HC595 avec la librairie Shifty ==== | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | Un gestionnaire 74HC595 flexible pour Arduino | ||
| + | |||
| + | La bibliothèque Shifty pour Arduino est un moyen très flexible de gérer les registres à décalage 74HC595. Il vous permet d' | ||
| + | |||
| + | <code c Prog_Test_Shifty> | ||
| + | #include < | ||
| + | |||
| + | // Declare the shift register | ||
| + | Shifty shift; | ||
| + | |||
| + | void setup() { | ||
| + | // Set the number of bits you have (multiples of 8) | ||
| + | shift.setBitCount(8); | ||
| + | |||
| + | // Set the clock, data, and latch pins you are using | ||
| + | // This also sets the pinMode for these pins | ||
| + | shift.setPins(11, | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | // writeBit works just like digitalWrite | ||
| + | shift.writeBit(1, | ||
| + | delay(500); | ||
| + | shift.writeBit(3, | ||
| + | delay(500); | ||
| + | shift.writeBit(1, | ||
| + | delay(500); | ||
| + | shift.writeBit(3, | ||
| + | |||
| + | delay(500); | ||
| + | } | ||
| + | </ | ||
| + | ==== Programme pour 74HC595 sans librairie ===== | ||
| + | |||
| + | <code c Prog2.ino> | ||
| + | int SER_Pin = 8; //pin 14 sur le 75HC595 | ||
| + | int RCLK_Pin = 9; //pin 12 sur le 75HC595 | ||
| + | int SRCLK_Pin = 10; //pin 11 sur le 75HC595 | ||
| + | |||
| + | #define number_of_74hc595s 1 //Combien combinez-vous de 74HC595 ? Ne pas toucher si 1 seul | ||
| + | |||
| + | #define numOfRegisterPins number_of_74hc595s * 8 | ||
| + | boolean registers[numOfRegisterPins]; | ||
| + | void setup(){ | ||
| + | pinMode(SER_Pin, | ||
| + | pinMode(RCLK_Pin, | ||
| + | pinMode(SRCLK_Pin, | ||
| + | //Reset tous les pins du 74HC595 | ||
| + | clearRegisters(); | ||
| + | writeRegisters(); | ||
| + | } | ||
| + | //Place tous les pins du 74HC595 à l' | ||
| + | void clearRegisters(){ | ||
| + | for(int i = numOfRegisterPins - 1; i >= 0; i--){ | ||
| + | registers[i] = LOW; | ||
| + | } | ||
| + | } | ||
| + | // | ||
| + | //Executer uniquement APRES que toutes les valeurs aient été programmées | ||
| + | void writeRegisters(){ | ||
| + | digitalWrite(RCLK_Pin, | ||
| + | for(int i = numOfRegisterPins - 1; i >= 0; i--){ | ||
| + | digitalWrite(SRCLK_Pin, | ||
| + | int val = registers[i]; | ||
| + | digitalWrite(SER_Pin, | ||
| + | digitalWrite(SRCLK_Pin, | ||
| + | } | ||
| + | digitalWrite(RCLK_Pin, | ||
| + | } | ||
| + | //Place un pin du 74HC595 à l' | ||
| + | void setRegisterPin(int index, int value){ | ||
| + | registers[index] = value; | ||
| + | } | ||
| + | void loop(){ | ||
| + | setRegisterPin(2, | ||
| + | setRegisterPin(3, | ||
| + | setRegisterPin(4, | ||
| + | setRegisterPin(5, | ||
| + | setRegisterPin(7, | ||
| + | writeRegisters(); | ||
| + | //Executer seulement une fois que toutes les valeurs ont été enregistrées comme vous le souhaitiez. | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Programmation 74HC595 en utilisant les bits du registre plus rapide mais plus compliqué ==== | ||
| + | |||
| + | <code c Prog3.ino> | ||
| + | // Broche connectée au ST_CP du 74HC595 | ||
| + | const int verrou = 11; | ||
| + | // Broche connectée au SH_CP du 74HC595 | ||
| + | const int horloge = 12; | ||
| + | // Broche connectée au DS du 74HC595 | ||
| + | const int data = 10; | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | // On met les broches en sortie | ||
| + | pinMode(verrou, | ||
| + | pinMode(horloge, | ||
| + | pinMode(data, | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | // on affiche les nombres de 0 à 255 en binaire | ||
| + | for (char i = 0; i<256; i++) | ||
| + | { | ||
| + | // On active le verrou le temps de transférer les données | ||
| + | digitalWrite(verrou, | ||
| + | // on envoi toutes les données grâce à notre belle fonction | ||
| + | envoi_ordre(data, | ||
| + | // et enfin on relâche le verrou | ||
| + | digitalWrite(verrou, | ||
| + | // une petite pause pour constater l' | ||
| + | delay(1000); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void envoi_ordre(int dataPin, int clockPin, boolean sens, char donnee) | ||
| + | { | ||
| + | // on va parcourir chaque bit de l' | ||
| + | for(int i=0; i<8; i++) | ||
| + | { | ||
| + | // on met l' | ||
| + | digitalWrite(clockPin, | ||
| + | // on met le bit de donnée courante en place | ||
| + | if(sens) | ||
| + | { | ||
| + | digitalWrite(dataPin, | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | digitalWrite(dataPin, | ||
| + | } | ||
| + | // enfin on remet l' | ||
| + | // faire prendre en compte cette dernière | ||
| + | digitalWrite(clockPin, | ||
| + | } | ||
| + | } | ||
| + | |||
| </ | </ | ||
/home/chanteri/www/fablab37110/data/attic/start/arduino/74hc595/programmes.1646733889.txt.gz · Dernière modification : (modification externe)
