Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * LED's DICE USING CHARLIE--PLEXING with millis() delays
- * 7 x LED's on just 4 x DIGITAL OUTPUT's
- *
- * LED2 LED3
- * LED4 LED1 LED4
- * LED3 LED2
- *
- * common anode and cathode (parallel) for LEDs 2 3 & 4
- * Use an ADC pin for the randomSeed
- *
- * BY R NcCleery
- * 10th FEBRUARY 2021
- *
- */
- #define Z (uint8_t)0
- #define II (uint8_t)2
- #define III (uint8_t)3
- #define IV (uint8_t)4
- #define V (uint8_t)5
- uint8_t leds[]{II,III,V,IV};
- int button(A0);
- uint8_t diceVal[][4]{
- {0,0,0,0},
- {1,0,0,0}, //One
- {0,1,0,0}, //Two
- {1,0,1,0}, //Three
- {0,1,1,0}, //Four
- {1,1,1,0}, //Five
- {0,1,1,1}, //Six
- };
- #define I (uint8_t)1
- #define VII (uint8_t)7
- #define XL (uint8_t)40
- #define LX (uint8_t)60
- bool throwDice = true;
- long ctRollDice = Z;
- uint8_t count = Z, diceNUM = Z;
- void setup(){
- pinMode(button, INPUT_PULLUP);
- for(uint8_t i = 0; i < IV; i++){
- pinMode(leds[i], OUTPUT);
- digitalWrite(leds[i], diceVal[diceNUM][i]);
- }
- uint8_t randomSeed(analogRead(button));
- }
- void loop(){
- uint8_t trigger = digitalRead(button);
- if(trigger == LOW){
- ctRollDice = millis();
- throwDice = true;
- }
- if(throwDice){
- if(count > XL){
- count = Z;
- diceNUM = random(I, VII);
- throwDice = false;
- }else{
- if(millis() - ctRollDice > LX){
- ctRollDice = millis();
- count++;
- diceNUM = random(I, VII);
- }else if(millis() - ctRollDice > XL){
- uint8_t diceNUM = Z;
- }
- }
- }
- for(uint8_t i = Z; i < IV; i++){
- digitalWrite(leds[i], diceVal[diceNUM][i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement