Simple control for ST M5451 LED driver.

Sample usage

#include "mbed.h"
#include "M5451.h"

M5451 m5451(D8, D7);

void toggleOneByOne(){
    for(char i = 0; i < m5451.outputs(); i++){
        m5451.toggleBit(i);
        m5451.update();
        wait_ms(250);
        m5451.toggleBit(i);
    }
}

int main() {
    while(1) {
        m5451.setAllBits(0);
        toggleOneByOne();
        m5451.setAllBits(1);
        toggleOneByOne();
    }
}
Committer:
jirrick
Date:
Sun Mar 01 11:41:57 2020 +0000
Revision:
1:db1e69c22bc6
Parent:
0:b21b3517a1d6
add toggleBit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jirrick 0:b21b3517a1d6 1 #ifndef JIRRICK_M5451_H
jirrick 0:b21b3517a1d6 2 #define JIRRICK_M5451_H
jirrick 0:b21b3517a1d6 3
jirrick 0:b21b3517a1d6 4 #include "mbed.h"
jirrick 0:b21b3517a1d6 5
jirrick 0:b21b3517a1d6 6 #define JIRRICK_M5451_WAIT 1
jirrick 0:b21b3517a1d6 7 #define JIRRICK_M5451_OUTPUTS 35
jirrick 0:b21b3517a1d6 8
jirrick 0:b21b3517a1d6 9 class M5451 {
jirrick 0:b21b3517a1d6 10 public:
jirrick 0:b21b3517a1d6 11 M5451(PinName dataPin, PinName clockPin);
jirrick 1:db1e69c22bc6 12 short outputs();
jirrick 0:b21b3517a1d6 13 void setState(uint64_t state);
jirrick 1:db1e69c22bc6 14 void setBit(short position, short value);
jirrick 1:db1e69c22bc6 15 void toggleBit(short position);
jirrick 1:db1e69c22bc6 16 void setAllBits(short value);
jirrick 0:b21b3517a1d6 17 void update();
jirrick 0:b21b3517a1d6 18 uint64_t getState();
jirrick 0:b21b3517a1d6 19
jirrick 0:b21b3517a1d6 20 private:
jirrick 0:b21b3517a1d6 21 DigitalOut _dataPin;
jirrick 0:b21b3517a1d6 22 DigitalOut _clockPin;
jirrick 0:b21b3517a1d6 23 uint64_t _state;
jirrick 1:db1e69c22bc6 24 void _send(short bit);
jirrick 0:b21b3517a1d6 25 };
jirrick 0:b21b3517a1d6 26
jirrick 0:b21b3517a1d6 27 #endif