2 * 2 working correctly.
This commit is contained in:
@@ -1,11 +1,85 @@
|
||||
void setup() {
|
||||
pinMode(2, OUTPUT);
|
||||
#include "TimerOne.h"
|
||||
|
||||
const byte cath_low = 3, cath_high = 2;
|
||||
const byte anode_start = 4;
|
||||
|
||||
void setup() {
|
||||
pinMode(cath_low, OUTPUT);
|
||||
pinMode(cath_high, OUTPUT);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
pinMode(anode_start + i, OUTPUT);
|
||||
}
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
Timer1.initialize();
|
||||
Timer1.setPeriod(1000);
|
||||
Timer1.attachInterrupt(displayOneLayer);
|
||||
}
|
||||
|
||||
byte LED_status = 0;
|
||||
byte currentDisplayLayer = 0;
|
||||
|
||||
void loop() {
|
||||
digitalWrite(2, HIGH);
|
||||
delay(2);
|
||||
digitalWrite(2, LOW);
|
||||
delay(14);
|
||||
// if (Serial.available()) {
|
||||
// char input = Serial.read();
|
||||
// if (input >= '0' && input < '9') {
|
||||
// int LED_num = input - '0';
|
||||
// LED_status ^= 1 << LED_num;
|
||||
// }
|
||||
// }
|
||||
// for (int i = 0; i < 8; i++) {
|
||||
// LED_status ^= 1 << i;
|
||||
// delay(75);
|
||||
// }
|
||||
|
||||
int count = 0;
|
||||
while (true) {
|
||||
randomSeed(analogRead(0));
|
||||
int num = random(0, 8);
|
||||
if (!(LED_status & (1 << num))) {
|
||||
count++;
|
||||
LED_status ^= 1 << num;
|
||||
delay(100);
|
||||
}
|
||||
if (count >= 8) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delay(500);
|
||||
|
||||
while (true) {
|
||||
randomSeed(analogRead(0));
|
||||
int num = random(0, 8);
|
||||
if (LED_status & (1 << num)) {
|
||||
count--;
|
||||
LED_status ^= 1 << num;
|
||||
delay(100);
|
||||
}
|
||||
|
||||
if (count <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delay(500);
|
||||
}
|
||||
|
||||
void displayOneLayer() {
|
||||
// Serial.println(LED_status, BIN);
|
||||
currentDisplayLayer = (currentDisplayLayer + 1) % 2;
|
||||
if (currentDisplayLayer == 0) {
|
||||
digitalWrite(cath_high, LOW);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
digitalWrite(anode_start + i, (LED_status >> i) & 1);
|
||||
}
|
||||
digitalWrite(cath_low, HIGH);
|
||||
} else {
|
||||
digitalWrite(cath_low, LOW);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
digitalWrite(anode_start + i, (LED_status >> (i + 4)) & 1);
|
||||
}
|
||||
digitalWrite(cath_high, HIGH);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user