时钟!
This commit is contained in:
@@ -299,10 +299,13 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
brightness %= 4;
|
brightness %= 4;
|
||||||
LED_status[z][x] =
|
|
||||||
(LED_status[z][x] & (~(3 << (y * 2)))) | (brightness << (y * 2));
|
|
||||||
LED_brightness[z][x] = (LED_brightness[z][x] & (~(3 << (y * 2)))) |
|
LED_brightness[z][x] = (LED_brightness[z][x] & (~(3 << (y * 2)))) |
|
||||||
(brightness << (y * 2));
|
(brightness << (y * 2));
|
||||||
|
if (LED_blinking_status[z][x] >> y & 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LED_status[z][x] =
|
||||||
|
(LED_status[z][x] & (~(3 << (y * 2)))) | (brightness << (y * 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_status(int x, int y, int z) {
|
static int get_status(int x, int y, int z) {
|
||||||
@@ -848,7 +851,7 @@ enum ClockStatus {
|
|||||||
Normal,
|
Normal,
|
||||||
AdjustingHour,
|
AdjustingHour,
|
||||||
AdjustingMinute,
|
AdjustingMinute,
|
||||||
}
|
};
|
||||||
|
|
||||||
int Cube::layer_count = 0;
|
int Cube::layer_count = 0;
|
||||||
int Cube::brightness_count = 0;
|
int Cube::brightness_count = 0;
|
||||||
@@ -983,7 +986,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (can_change_mode) {
|
if (can_change_mode && clock_status == ClockStatus::Normal) {
|
||||||
if (analogRead(JOYSTICK_VRY) > 974) {
|
if (analogRead(JOYSTICK_VRY) > 974) {
|
||||||
current_mode = (enum Modes)(current_mode + 1) % 5;
|
current_mode = (enum Modes)(current_mode + 1) % 5;
|
||||||
can_change_mode = false;
|
can_change_mode = false;
|
||||||
@@ -1111,25 +1114,30 @@ void rain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void clock() {
|
void clock() {
|
||||||
int VRX_status = analogRead(JOYSTICK_VRX)
|
int VRX_status = analogRead(JOYSTICK_VRX);
|
||||||
if (clock_waiting_for_new_command) {
|
if (clock_waiting_for_new_command) {
|
||||||
if (clock_status == ClockStatus::AdjustingHour) {
|
if (clock_status == ClockStatus::AdjustingHour) {
|
||||||
if (VRX_status < 50) {
|
if (VRX_status < 50) {
|
||||||
clock_hour = (clock_hour + 23) % 24;
|
clock_hour = (clock_hour + 23) % 24;
|
||||||
|
clock_waiting_for_new_command = false;
|
||||||
}
|
}
|
||||||
else if (VRX_status > 974) {
|
else if (VRX_status > 974) {
|
||||||
clock_hour = (clock_hour + 1) % 24;
|
clock_hour = (clock_hour + 1) % 24;
|
||||||
|
clock_waiting_for_new_command = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (clock_status == ClockStatus::AdjustingMinute) {
|
else if (clock_status == ClockStatus::AdjustingMinute) {
|
||||||
if (VRX_status < 50) {
|
if (VRX_status < 50) {
|
||||||
clock_minute = (clock_minute + 59) % 60;
|
clock_minute = (clock_minute + 59) % 60;
|
||||||
|
clock_waiting_for_new_command = false;
|
||||||
}
|
}
|
||||||
else if (VRX_status > 974) {
|
else if (VRX_status > 974) {
|
||||||
clock_minute = (clock_minute + 1) % 60;
|
clock_minute = (clock_minute + 1) % 60;
|
||||||
|
clock_waiting_for_new_command = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (VRX_status > 400 && VRX_status < 624) {
|
if (VRX_status > 400 && VRX_status < 624) {
|
||||||
clock_waiting_for_new_command = true;
|
clock_waiting_for_new_command = true;
|
||||||
}
|
}
|
||||||
@@ -1370,30 +1378,43 @@ void on_joystick_button() {
|
|||||||
if (current_mode == Modes::Clock) {
|
if (current_mode == Modes::Clock) {
|
||||||
switch (clock_status) {
|
switch (clock_status) {
|
||||||
case ClockStatus::Normal: {
|
case ClockStatus::Normal: {
|
||||||
|
if (DEBUG) {
|
||||||
|
Serial.println("Start adjusting hour");
|
||||||
|
}
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
for (int j = 4; j < 8; j++) {
|
for (int j = 4; j < 8; j++) {
|
||||||
Cube::LED_blinking_status[i][j] = 0xff;
|
// Cube::set_blinking(i, 1, j);
|
||||||
|
Cube::LED_blinking_status[j][i] = 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Cube::LED_blinking_status[0][0] = 0x1;
|
||||||
clock_status = ClockStatus::AdjustingHour;
|
clock_status = ClockStatus::AdjustingHour;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ClockStatus::AdjustingHour: {
|
case ClockStatus::AdjustingHour: {
|
||||||
|
if (DEBUG) {
|
||||||
|
Serial.println("Start adjucting minute");
|
||||||
|
}
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
for (int j = 4; j < 8; j++) {
|
for (int j = 4; j < 8; j++) {
|
||||||
Cube::LED_blinking_status[i][j] = 0;
|
// Cube::unset_blinking(i, 1, j);
|
||||||
|
Cube::LED_blinking_status[j][i] = 0;
|
||||||
}
|
}
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
Cube::LED_blinking_status[i][j] = 0xff;
|
// Cube::set_blinking(i, 0, j);
|
||||||
|
Cube::LED_blinking_status[j][i] = 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clock_status = ClockStatus::AdjustingMinute;
|
clock_status = ClockStatus::AdjustingMinute;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ClockStatus::AdjustingMinute: {
|
case ClockStatus::AdjustingMinute: {
|
||||||
|
if (DEBUG) {
|
||||||
|
Serial.println("Normal mode");
|
||||||
|
}
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
Cube::LED_blinking_status[i][j] = 0;
|
Cube::LED_blinking_status[j][i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clock_sec = 0;
|
clock_sec = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user