Compare commits
4 Commits
378d387986
...
df4e264dba
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df4e264dba
|
||
|
|
f0d7ac873e
|
||
|
|
5eb2aec06a
|
||
|
|
246df58947
|
130
8By8/8By8.ino
130
8By8/8By8.ino
@@ -20,7 +20,7 @@
|
||||
#define MAG_UPDATE 0x08
|
||||
#define READ_UPDATE 0x80
|
||||
|
||||
#define DEBUG true
|
||||
#define DEBUG false
|
||||
#define TRACE false
|
||||
|
||||
// 3 width, 4 height
|
||||
@@ -166,6 +166,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
if (WitSetBandwidth(BANDWIDTH_256HZ) != WIT_HAL_OK) {
|
||||
Serial.println("Set Bandwidth Error");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (WitSetContent(RSW_ANGLE | RSW_ACC | RSW_GYRO) != WIT_HAL_OK) {
|
||||
Serial.println("Set send content: angle, acc, and GYRO Error");
|
||||
return false;
|
||||
@@ -309,10 +314,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 +862,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 +903,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 +1006,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 +1054,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 +1134,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() {
|
||||
@@ -1163,7 +1225,8 @@ void words() {
|
||||
}
|
||||
else {
|
||||
Serial.print(display_string[next_char_ptr]);
|
||||
Cube::draw_letter(0, 7, 7, display_string[next_char_ptr] - '0' + 26, 2, 3);
|
||||
Cube::draw_letter(0, 7, 7, display_string[next_char_ptr] - '0' + 26, 2,
|
||||
3);
|
||||
}
|
||||
|
||||
next_char_ptr++;
|
||||
@@ -1246,8 +1309,8 @@ void calculate_and_draw() {
|
||||
if (SensorReader::angle.z - z_ref > 40.0) {
|
||||
if (DEBUG) {
|
||||
Serial.println(SensorReader::angle.z);
|
||||
Serial.println("e");
|
||||
}
|
||||
Serial.println("Zoom out");
|
||||
zoom /= 2.0;
|
||||
need_reevaluate = true;
|
||||
waiting_for_command = false;
|
||||
@@ -1255,8 +1318,8 @@ void calculate_and_draw() {
|
||||
else if (SensorReader::angle.z - z_ref < -40.0) {
|
||||
if (DEBUG) {
|
||||
Serial.println(SensorReader::angle.z);
|
||||
Serial.println("f");
|
||||
}
|
||||
Serial.println("Zoom in");
|
||||
zoom *= 2.0;
|
||||
need_reevaluate = true;
|
||||
waiting_for_command = false;
|
||||
@@ -1391,6 +1454,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) {
|
||||
|
||||
Reference in New Issue
Block a user