Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int LEEG_DISPLAY = 1;
- const int ROLLEN = 2;
- const int UITROLLEN = 3;
- const int TOON_WAARDE = 4;
- int huidigeToestand = LEEG_DISPLAY;
- const int SEQUENCES = 16;
- byte LEDsequence[SEQUENCES] = { B11111100, // 0
- B01100000, // 1
- B11011010, // 2
- B11110010, // 3
- B01100110, // 4
- B10110110, // 5
- B10111110, // 6
- B11100000, // 7
- B11111110, // 8
- B11110110, // 9
- B11101110, // A
- B00111110, // B
- B10011100, // C
- B01111010, // D
- B10011110, // E
- B10001110 // F
- };
- const int dataPin = 6; // loopt naar 14 DS
- const int latchPin = 8; // loopt naar 12 ST_CP
- const int clockPin = 10; // loopt naar 11 SH_CP
- unsigned long int previousMillis;
- int INTERVAL = 1000;
- void setup() {
- Serial.begin(9600);
- initializePins();
- previousMillis = 0 - INTERVAL;
- serialFlush();
- }
- void serialFlush() {
- while (Serial.available() > 0)
- {
- Serial.read();
- }
- }
- void loop() {
- listenSerialPort();
- currentSeq();
- }
- void listenSerialPort() {
- if (Serial.available()) {
- checkEditInput(Serial.read());
- }
- }
- void initializePins() {
- pinMode(dataPin, OUTPUT);
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- }
- void checkEditInput(char input) {
- Serial.print(input);
- switch (input) {
- case 'S':
- huidigeToestand = ROLLEN;
- loopThroughSequences();
- break;
- case 'H':
- huidigeToestand = UITROLLEN;
- loopThroughSequences();
- break;
- case 'E':
- huidigeToestand = LEEG_DISPLAY;
- turnOff();
- break;
- }
- }
- void currentSeq() {
- switch (huidigeToestand) {
- case LEEG_DISPLAY:
- turnOff();
- break;
- case ROLLEN:
- loopThroughSequences();
- break;
- case UITROLLEN:
- loopThroughSequences();
- break;
- case TOON_WAARDE:
- break;
- }
- }
- int index;
- void loopThroughSequences() {
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= INTERVAL) {
- if ( huidigeToestand == ROLLEN ) {
- int spd = -100;
- speedFix(spd);
- }
- if ( huidigeToestand == UITROLLEN | huidigeToestand == TOON_WAARDE) {
- int spd = 100;
- speedFix(spd);
- showRoll(LEDsequence[index]);
- previousMillis = 0;
- }
- myfnUpdateDisplay(LEDsequence[index]);
- index++;
- if (index >= SEQUENCES) {
- index = 0;
- }
- previousMillis = currentMillis;
- }
- }
- void showRoll (byte bits) {
- unsigned long currentMillis = millis();
- if ( currentMillis - previousMillis >= 3500) {
- myfnUpdateDisplay(bits);
- }
- }
- void speedFix(int spd) {
- if (INTERVAL + spd >= 100) {
- INTERVAL += spd;
- }
- }
- void turnOff() {
- INTERVAL = 1000;
- index = 0;
- int lampsOff = B00000000;
- myfnUpdateDisplay(lampsOff);
- }
- void myfnUpdateDisplay(byte eightBits) {
- digitalWrite(latchPin, LOW); // prepare shift register for data
- shiftOut(dataPin, clockPin, LSBFIRST, eightBits); // send data
- digitalWrite(latchPin, HIGH); // update display
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement