Merge branch '尝试clock'

This commit is contained in:
unlockable
2023-09-10 12:03:23 +08:00

View File

@@ -309,10 +309,13 @@ public:
return;
}
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)))) |
(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) {
@@ -854,6 +857,12 @@ enum Modes {
Words,
};
enum ClockStatus {
Normal,
AdjustingHour,
AdjustingMinute,
};
int Cube::layer_count = 0;
int Cube::brightness_count = 0;
uint16_t Cube::LED_status[8][8] = {0};
@@ -889,6 +898,10 @@ int letter_create_layer_count = 0;
// When count to 7, it's time to draw the new letter.
int next_char_ptr = 0;
int clock_hour = 0, clock_minute = 0, clock_sec = 0, clock_sec_flip = 0;
ClockStatus clock_status;
bool clock_waiting_for_new_command = true;
void setup() {
for (int i = 22; i < 46; i++) {
pinMode(i, OUTPUT);
@@ -988,7 +1001,7 @@ void setup() {
}
void loop() {
if (can_change_mode) {
if (can_change_mode && clock_status == ClockStatus::Normal) {
if (analogRead(JOYSTICK_VRY) > 974) {
current_mode = (enum Modes)(current_mode + 1) % 5;
can_change_mode = false;
@@ -1036,6 +1049,18 @@ ISR(TIMER4_COMPA_vect) {
ISR(TIMER5_COMPA_vect) {
SensorReader::read_data_from_sensor_interrupt();
if (clock_status == ClockStatus::Normal) {
clock_sec_flip++;
clock_sec += clock_sec_flip / 4;
clock_minute += clock_sec / 60;
clock_hour += clock_minute / 60;
clock_sec_flip %= 4;
clock_sec %= 60;
clock_minute %= 60;
clock_hour %= 24;
}
}
void cube() {
@@ -1104,7 +1129,39 @@ void rain() {
}
void clock() {
return;
int VRX_status = analogRead(JOYSTICK_VRX);
if (clock_waiting_for_new_command) {
if (clock_status == ClockStatus::AdjustingHour) {
if (VRX_status < 50) {
clock_hour = (clock_hour + 23) % 24;
clock_waiting_for_new_command = false;
}
else if (VRX_status > 974) {
clock_hour = (clock_hour + 1) % 24;
clock_waiting_for_new_command = false;
}
}
else if (clock_status == ClockStatus::AdjustingMinute) {
if (VRX_status < 50) {
clock_minute = (clock_minute + 59) % 60;
clock_waiting_for_new_command = false;
}
else if (VRX_status > 974) {
clock_minute = (clock_minute + 1) % 60;
clock_waiting_for_new_command = false;
}
}
}
else {
if (VRX_status > 400 && VRX_status < 624) {
clock_waiting_for_new_command = true;
}
}
Cube::draw_num(0, 1, 7, clock_hour / 10, 2, 3);
Cube::draw_num(4, 1, 7, clock_hour % 10, 2, 3);
Cube::draw_num(0, 0, 3, clock_minute / 10, 2, 3);
Cube::draw_num(4, 0, 3, clock_minute % 10, 2, 3);
}
void words() {
@@ -1391,6 +1448,57 @@ void on_joystick_button() {
Serial.println("Reset position.");
return;
}
if (current_mode == Modes::Clock) {
switch (clock_status) {
case ClockStatus::Normal: {
if (DEBUG) {
Serial.println("Start adjusting hour");
}
for (int i = 0; i < 8; i++) {
for (int j = 4; j < 8; j++) {
// Cube::set_blinking(i, 1, j);
Cube::LED_blinking_status[j][i] = 0xff;
}
}
// Cube::LED_blinking_status[0][0] = 0x1;
clock_status = ClockStatus::AdjustingHour;
break;
}
case ClockStatus::AdjustingHour: {
if (DEBUG) {
Serial.println("Start adjucting minute");
}
for (int i = 0; i < 8; i++) {
for (int j = 4; j < 8; j++) {
// Cube::unset_blinking(i, 1, j);
Cube::LED_blinking_status[j][i] = 0;
}
for (int j = 0; j < 4; j++) {
// Cube::set_blinking(i, 0, j);
Cube::LED_blinking_status[j][i] = 0xff;
}
}
clock_status = ClockStatus::AdjustingMinute;
break;
}
case ClockStatus::AdjustingMinute: {
if (DEBUG) {
Serial.println("Normal mode");
}
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 4; j++) {
Cube::LED_blinking_status[j][i] = 0;
}
}
clock_sec = 0;
clock_sec_flip = 0;
clock_status = ClockStatus::Normal;
break;
}
default:
clock_status = ClockStatus::Normal;
}
}
}
String display_mode_name(Modes mode_name) {