尝试clock
This commit is contained in:
@@ -844,6 +844,12 @@ enum Modes {
|
|||||||
Words,
|
Words,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ClockStatus {
|
||||||
|
Normal,
|
||||||
|
AdjustingHour,
|
||||||
|
AdjustingMinute,
|
||||||
|
}
|
||||||
|
|
||||||
int Cube::layer_count = 0;
|
int Cube::layer_count = 0;
|
||||||
int Cube::brightness_count = 0;
|
int Cube::brightness_count = 0;
|
||||||
uint16_t Cube::LED_status[8][8] = {0};
|
uint16_t Cube::LED_status[8][8] = {0};
|
||||||
@@ -874,6 +880,10 @@ byte cube_step = 1;
|
|||||||
|
|
||||||
bool rain_create_new = false;
|
bool rain_create_new = false;
|
||||||
|
|
||||||
|
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() {
|
void setup() {
|
||||||
for (int i = 22; i < 46; i++) {
|
for (int i = 22; i < 46; i++) {
|
||||||
pinMode(i, OUTPUT);
|
pinMode(i, OUTPUT);
|
||||||
@@ -1021,6 +1031,18 @@ ISR(TIMER4_COMPA_vect) {
|
|||||||
|
|
||||||
ISR(TIMER5_COMPA_vect) {
|
ISR(TIMER5_COMPA_vect) {
|
||||||
SensorReader::read_data_from_sensor_interrupt();
|
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() {
|
void cube() {
|
||||||
@@ -1089,7 +1111,34 @@ void rain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void clock() {
|
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;
|
||||||
|
}
|
||||||
|
else if (VRX_status > 974) {
|
||||||
|
clock_hour = (clock_hour + 1) % 24;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (clock_status == ClockStatus::AdjustingMinute) {
|
||||||
|
if (VRX_status < 50) {
|
||||||
|
clock_minute = (clock_minute + 59) % 60;
|
||||||
|
}
|
||||||
|
else if (VRX_status > 974) {
|
||||||
|
clock_minute = (clock_minute + 1) % 60;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} 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() {
|
void words() {
|
||||||
@@ -1318,6 +1367,44 @@ void on_joystick_button() {
|
|||||||
Serial.println("Reset position.");
|
Serial.println("Reset position.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (current_mode == Modes::Clock) {
|
||||||
|
switch (clock_status) {
|
||||||
|
case ClockStatus::Normal: {
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
for (int j = 4; j < 8; j++) {
|
||||||
|
Cube::LED_blinking_status[i][j] = 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clock_status = ClockStatus::AdjustingHour;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ClockStatus::AdjustingHour: {
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
for (int j = 4; j < 8; j++) {
|
||||||
|
Cube::LED_blinking_status[i][j] = 0;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
Cube::LED_blinking_status[i][j] = 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clock_status = ClockStatus::AdjustingMinute;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ClockStatus::AdjustingMinute: {
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
Cube::LED_blinking_status[i][j] = 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) {
|
String display_mode_name(Modes mode_name) {
|
||||||
|
|||||||
Reference in New Issue
Block a user