3. Programming control

The desired animations can now be realized with almost any microcontroller platform.

microcontroller programming

Create a program to create attractive animations of your LED-Signs for the selected microcontroller platform.

 

If you’re using the Arduino related platforms for the first time, the Arduino Applications tutorial will help you get started.

The code below shows the control of the LED sign using the interface board. To create your own animations, all you have to do now is adjust the loop area according to your own wishes.

#include <ESP8266WiFi.h>

class WEMOSLEDCtrl {
  const int ENABLEOUTPUT = D0;
  const int SHIFTREGCLR = D5;
  const int SERIN = D6;
  const int SHIFTREGCLK = D4;
  const int REGCLK = D3;
  const int BUTTON = D7;
  const int LDR = A0;

  unsigned int value;

public:
  
  void init() {
    pinMode(ENABLEOUTPUT, OUTPUT);   
    pinMode(SHIFTREGCLR, OUTPUT);   
    pinMode(SERIN, OUTPUT);   
    pinMode(SHIFTREGCLK, OUTPUT);   
    pinMode(REGCLK, OUTPUT);   
    pinMode(BUTTON, INPUT);

    digitalWrite(ENABLEOUTPUT, HIGH); // active low!
    digitalWrite(SHIFTREGCLR, HIGH); // active low!
  }
  
  void unsetAll() {
    this->value = 0;
  }

  void setAll() {
    this->value=0xFF;
  }

  void set(int index) {
    if(index>=0 && index<8)
      this->value |= 1 << index;
  }
  
  void unset(int index) {
    if(index>=0 && index<8)
      this->value &= !(1 << index);
  }
  
  void commit() {
    for(int i=0; i<8; i++) {
      digitalWrite(SERIN, (this->value>>i) & 0x01); // Lege Pegel des jeweiligen Bits an Eingang
      // aktiviere Schiebeaktion
      digitalWrite(SHIFTREGCLK, HIGH); 
      delay(100);
      digitalWrite(SHIFTREGCLK, LOW);       
      delay(100);
    }
    // schalte Ausgang aus
    digitalWrite(ENABLEOUTPUT, HIGH); // active low!
    // Übertrage Schiebregisterinhalt an Ausgangsregister
    digitalWrite(REGCLK, HIGH); 
    delay(100);
    digitalWrite(REGCLK, LOW); 
    // schalte Ausgang ein
    delay(100);
    digitalWrite(ENABLEOUTPUT, LOW); // active low!
  }  
};

WEMOSLEDCtrl ledsign;

void setup() {
  ledsign.init();
}

void loop() {  
  // change your desired behaviour
  
  // switch on all LEDs 
  ledsign.setAll();
  ledsign.commit();  
  
  delay(1000);
  
  // switch off all LEDs 
  ledsign.unsetAll();
  ledsign.commit();  
  delay(1000);
  
  // switch on LED1 and LED3 
  ledsign.set(0);
  ledsign.set(2);
  ledsign.commit();  
  delay(1000);
}

Leave a Reply