Étape 3: programmation
J’ai utilisé cette bibliothèque, qui offre un moyen très facile de contrôler notre affichage 7 segments : il prend en charge le point décimal, lettres (ce qui n’est pas fière allure sur un tel écran peu)
Il y a même un PDF décrivant la façon de le faire !
Cette esquisse utilise interrompt donc l’Arduino peut attendre série et utiliser l’affichage. Sans cela, l’écran serait instantanément retourner au noir après l’affichage de quelque chose.
Si votre écran est Cathode commune, vous devez remplacer disp.setCommonAnode() ; avec disp.setCommonCathode() ;
#include <sevenseg.h> SevenSeg disp(12,8,4,6,7,11,3); // here you put the pins that are connected to the segments // in alphabetical order : A,B,C,D,E,F,G const int numOfDigits=3; int digitPins[numOfDigits]={13,10,9}; String inputString = ""; boolean stringComplete = false void setup() { disp.setDigitPins(numOfDigits,digitPins); disp.setDPPin(5); // set the pin for the Decimal Point, if you have one disp.setCommonAnode(); // REPLACE THIS WITH disp.setCommonCathode(); IF YOUR DISPLAY IS COMMON CATHODE disp.setTimer(2); disp.startTimer(); Serial.begin(9600); } void loop() { if (stringComplete) { Serial.println(inputString); disp.write(inputString); inputString = ""; // clear the string: stringComplete = false; } } void serialEvent() { while (Serial.available()) { char inChar = (char)Serial.read(); // add it to the inputString: if(inChar != '\n') { inputString += inChar; } // if the incoming character is a newline, set a flag // so the main loop can do something about it: else { stringComplete = true; } } } ISR(TIMER2_COMPA_vect) { disp.interruptAction(); //attaches the timer to the interrupt }