-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.ino
1794 lines (1491 loc) · 48.4 KB
/
screen.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//====================== TASK SCHEDULER ======================
typedef struct task {
int state;
unsigned long period;
unsigned long prev_time;
int (*TickFct)(int );
} task;
const unsigned char task_num = 7;
const unsigned char period = 1;
task tasks[task_num]; // array of tasks
//====================== GLOBAL VARIABLES ======================
bool game_on = false;
bool start_endgame = false;
bool end_song = false;
bool end_scroll = false;
bool end_endgame = true;
bool end_game = false;
//scores
unsigned long score = 0;
unsigned long max_combo = 0;
//unsigned long current_combo = 0;
//unsigned long great_combo = 0;
//unsigned long perfect_combo = 0;
unsigned long total_miss = 0;
unsigned long total_bad = 0;
unsigned long total_great = 0;
unsigned long total_perfect = 0;
//====================== NOTE FREQUENCY ======================
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#define REST 0
//====================== MUSIC SYSTEM SM VARIABLES ======================
// change this to make the song slower or faster
const char tempo = 114;
// change this to whichever pin you want to use
const char buzzer = 22;
// notes of the melody followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!
int melody[] = {
REST,4, REST,4, REST,4, REST,4, REST,4, REST,4, REST,4, REST,4,
REST,4, REST,4, REST,4, REST,4, REST,4, REST,4, REST,4, REST,4,
REST,4, REST,4, REST,4, REST,4,
REST,8, NOTE_GS4,8, NOTE_GS4,8, NOTE_A4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_E4,4,
REST,8, NOTE_GS4,8, NOTE_GS4,8, NOTE_A4,8, NOTE_B4,8, NOTE_GS4,8, NOTE_E4,4,
REST,8, NOTE_FS4,8, NOTE_FS4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_DS4,8, NOTE_B3,4,
NOTE_FS4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_E4,8, NOTE_CS4,4, REST,4,
REST,4, REST,4, NOTE_GS5,8, NOTE_CS5,8, NOTE_GS5,8, NOTE_CS5,16, NOTE_GS5,16, REST,16, NOTE_CS5,16, NOTE_GS5,8, NOTE_CS5,8, NOTE_GS5,8,
NOTE_GS5,8, NOTE_B4,8, NOTE_GS5,8, NOTE_B5,16, NOTE_GS5,16, REST,16, NOTE_B4,16, NOTE_GS5,8, NOTE_B5,8, NOTE_GS5,8,
NOTE_FS5,8, NOTE_B5,8, NOTE_FS5,8, NOTE_B5,16, NOTE_FS5,16, REST,16, NOTE_B4,16, NOTE_FS5,8, NOTE_B5,8, NOTE_FS5,8,
NOTE_GS5,8, NOTE_CS5,8, NOTE_GS5,8, NOTE_CS5,16, NOTE_GS5,16, REST,16, NOTE_CS4,16, NOTE_GS5,8, NOTE_GS3,8, NOTE_GS3,8,
REST,4, REST,4, NOTE_CS4,-8, NOTE_CS4,16, NOTE_CS4,8, NOTE_DS4,8, NOTE_E4,4, REST,4,
REST,4, NOTE_E4,-8, NOTE_E4,16, NOTE_E4,8, NOTE_FS4,8, NOTE_GS4,4, REST,4,
NOTE_FS4,4, NOTE_FS4,8, NOTE_DS4,8, NOTE_B3,4, NOTE_DS4,4,
NOTE_E4,8, NOTE_FS4,8, NOTE_E4,8, NOTE_DS4,8, NOTE_CS4,4, REST,4,
NOTE_CS4,-8, NOTE_CS4,16, NOTE_CS4,8, NOTE_DS4,8, NOTE_E4,4, REST,4,
NOTE_DS4,16, NOTE_E4,8, NOTE_DS4,16, NOTE_E4,8, NOTE_FS4,8, NOTE_GS4,4, REST,4,
NOTE_FS4,4, NOTE_FS4,8, NOTE_DS4,8, NOTE_B3,4, NOTE_DS4,4,
NOTE_E4,8, NOTE_FS4,8, NOTE_E4,8, NOTE_DS4,8, NOTE_CS4,4, REST,4,
NOTE_GS4,4, NOTE_GS4,8, NOTE_B4,8, NOTE_CS5,4, NOTE_GS4,8, NOTE_B4,8,
NOTE_CS5,8, NOTE_E5,8, NOTE_CS5,8, NOTE_B4,8, NOTE_GS4,4, REST,4,
NOTE_FS4,4, NOTE_FS4,8, NOTE_GS4,8, NOTE_B4,4, NOTE_GS4,8, NOTE_E4,8,
NOTE_FS4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_E4,8, NOTE_CS4,4, REST, 4,
NOTE_GS4,4, NOTE_GS4,8, NOTE_B4,8, NOTE_CS5,4, NOTE_GS4,8, NOTE_B4,8,
NOTE_CS5,8, NOTE_E5,8, NOTE_CS5,8, NOTE_B4,8, NOTE_GS4,4, REST,4,
NOTE_FS4,4, NOTE_FS4,8, NOTE_GS4,8, NOTE_B4,4, NOTE_GS4,8, NOTE_E4,8,
NOTE_FS4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_E4,8, NOTE_CS4,4, REST, 4,
REST,4, REST,4, NOTE_GS5,8, NOTE_CS5,8, NOTE_GS5,8, NOTE_CS5,16, NOTE_GS5,16, REST,16, NOTE_CS5,16, NOTE_GS5,8, NOTE_CS5,8, NOTE_GS5,8,
NOTE_GS5,8, NOTE_B4,8, NOTE_GS5,8, NOTE_B5,16, NOTE_GS5,16, REST,16, NOTE_B4,16, NOTE_GS5,8, NOTE_B5,8, NOTE_GS5,8,
NOTE_FS5,8, NOTE_B5,8, NOTE_FS5,8, NOTE_B5,16, NOTE_FS5,16, REST,16, NOTE_B4,16, NOTE_FS5,8, NOTE_B5,8, NOTE_FS5,8,
NOTE_GS5,8, NOTE_CS5,8, NOTE_GS5,8, NOTE_CS5,16, NOTE_GS5,16, REST,16, NOTE_CS4,16, NOTE_GS5,8, NOTE_GS3,8, NOTE_GS3,8,
NOTE_CS4,-8, NOTE_CS4,16, NOTE_CS4,8, NOTE_DS4,8, NOTE_E4,4, REST,4,
NOTE_DS4,16, NOTE_E4,8, NOTE_DS4,16, NOTE_E4,8, NOTE_FS4,8, NOTE_GS4,4, REST,4,
NOTE_FS4,4, NOTE_FS4,8, NOTE_DS4,8, NOTE_B3,4, NOTE_DS4,4,
NOTE_E4,8, NOTE_FS4,8, NOTE_E4,8, NOTE_DS4,8, NOTE_CS4,4, REST,4,
NOTE_GS4,4, NOTE_GS4,8, NOTE_B4,8, NOTE_CS5,4, NOTE_GS4,8, NOTE_B4,8,
NOTE_CS5,8, NOTE_E5,8, NOTE_CS5,8, NOTE_B4,8, NOTE_GS4,4, REST,4,
NOTE_FS4,4, NOTE_FS4,8, NOTE_GS4,8, NOTE_B4,4, NOTE_GS4,8, NOTE_E4,8,
NOTE_FS4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_E4,8, NOTE_CS4,4, REST, 4,
NOTE_GS4,4, NOTE_GS4,8, NOTE_B4,8, NOTE_CS5,4, NOTE_GS4,8, NOTE_B4,8,
NOTE_CS5,8, NOTE_E5,8, NOTE_CS5,8, NOTE_B4,8, NOTE_GS4,4, REST,4,
NOTE_FS4,4, NOTE_FS4,8, NOTE_GS4,8, NOTE_B4,4, NOTE_GS4,8, NOTE_E4,8,
NOTE_FS4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_E4,8, NOTE_CS4,4, REST, 4,
REST,8, NOTE_GS4,8, NOTE_GS4,8, NOTE_A4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_E4,4,
REST,8, NOTE_GS4,8, NOTE_GS4,8, NOTE_A4,8, NOTE_B4,8, NOTE_GS4,8, NOTE_E4,4,
REST,8, NOTE_FS4,8, NOTE_FS4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_DS4,8, NOTE_B3,4,
NOTE_FS4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_E4,8, NOTE_CS4,4, REST,4,
REST,8, NOTE_GS4,8, NOTE_GS4,8, NOTE_A4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_E4,4,
REST,8, NOTE_GS4,8, NOTE_GS4,8, NOTE_A4,8, NOTE_B4,8, NOTE_GS4,8, NOTE_E4,4,
REST,8, NOTE_FS4,8, NOTE_FS4,8, NOTE_GS4,8, NOTE_FS4,8, NOTE_DS4,8, NOTE_B3,4,
NOTE_FS3,8, NOTE_GS3,8, NOTE_FS3,8, NOTE_E3,8, NOTE_CS3,4, REST,4,
REST,4, REST,4,
};
// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes = sizeof(melody)/sizeof(melody[0])/2;
// this calculates the duration of a whole note in ms (60s/tempo)*4 beats
int wholenote = (60000 * 4) / tempo;
int divider = 0;
//====================== SPI VARIABLES ======================
#include <SPI.h>
//buff for received message from K64F
char buff [255];
volatile byte indx;
volatile boolean process;
//initialize button presses
bool l = false;
bool d = false;
bool u = false;
bool r = false;
bool start = false;
//====================== LCD SCREEN ======================
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs1 = 43, en1 = 41, d4_1 = 39, d5_1 = 37, d6_1 = 35, d7_1 = 33;
LiquidCrystal lcd1(rs1, en1, d4_1, d5_1, d6_1, d7_1);
const int rs2 = 42, en2 = 40, d4_2 = 38, d5_2 = 36, d6_2 = 34, d7_2 = 32;
LiquidCrystal lcd2(rs2, en2, d4_2, d5_2, d6_2, d7_2);
//====================== START GAME SM VARIABLES ======================
//button input
const char end_display_led_pin = 23;
const char game_led_pin = 25;
const char start_btn = 28;
//temprary
const char l_btn = 24;
const char d_btn = 26;
const char u_btn = 48;
const char r_btn = 46;
//====================== TFT DISPLAY ======================
#include <Elegoo_GFX.h> // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h> // Touch Support
//#include "Adafruit_GFX.h"
//#include "MCUFRIEND_kbv.h"
#define TS_MINX 920
#define TS_MINY 120
#define TS_MAXX 150
#define TS_MAXY 940
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// macros for color (16 bit)
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
enum ARROWS{L, D, U, R} ARROW;
int map_sequence[] = {
U, R, U, R, U, L, U, L,
U, R, U, L, U, R, R, R,
R, L, L, L, R, D, L, U,
R, L, R, R, R, L, L, L,
R, R, D, L, U, R, L, R,
U, U, R, R, U, L, D, U,
D, L, R, L, D, U, U, U,
R, R, U, L, D, U, D, R,
L, R, U, D, D, R, D, R,
D, U, D, U, D, R, D, R,
D, L, R, D, R, L, U, U,
R, L, U, U, R, R, U, L,
D, U, D, L, R, L, D, U,
U, U, R, R, U, L, D, U,
D, R, D, R, U, D, D, R,
D, L, D, R, D, L, U, D,
R, D, L, D, R, D, L, D,
R, U, D, R, U, U, U, R
};
//delay between each arrow is 30 ms
int arrow_position[] = {
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320,
320, 320, 320, 320, 320, 320, 320, 320
};
bool is_arrow_displayed[] = {
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false
};
unsigned char map_sequence_size = sizeof(map_sequence)/sizeof(map_sequence[0]);
void line() {
tft.drawFastHLine(0, 50, 240, WHITE);
tft.drawFastHLine(0, 49, 240, WHITE);
}
// map components
void l_rect(int y) { // X O O O
tft.fillRect(24, y - 1, 30, 1, BLACK);
tft.fillRect(24, y, 30, 6, BLUE);
tft.fillRect(24, y + 6, 30, 1, BLACK);
if (y == 60) {line();}
if (y == 59) {line();}
if (y == 58) {line();}
if (y == 57) {line();}
if (y == 56) {line();}
if (y == 55) {line();}
if (y == 54) {line();}
if (y == 53) {line();}
if (y == 52) {line();}
if (y == 51) {line();}
if (y == 50) {line();}
if (y == 49) {line();}
if (y == 48) {line();}
if (y == 47) {line();}
if (y == 46) {line();}
if (y == 45) {line();}
if (y == 44) {line();}
if (y == 43) {line();}
if (y == 42) {line();}
if (y == 41) {line();}
if (y == 40) {line();}
if (y == 39) {line();}
if (y == 38) {line();}
}
void d_rect(int y) { // O X O O
tft.fillRect(78, y - 1, 30, 1, BLACK);
tft.fillRect(78, y, 30, 6, RED);
tft.fillRect(78, y + 6, 30, 1, BLACK);
if (y == 65) {line();}
if (y == 64) {line();}
if (y == 63) {line();}
if (y == 62) {line();}
if (y == 61) {line();}
if (y == 60) {line();}
if (y == 59) {line();}
if (y == 58) {line();}
if (y == 57) {line();}
if (y == 56) {line();}
if (y == 55) {line();}
if (y == 54) {line();}
if (y == 53) {line();}
if (y == 52) {line();}
if (y == 51) {line();}
if (y == 50) {line();}
if (y == 49) {line();}
if (y == 48) {line();}
if (y == 47) {line();}
if (y == 46) {line();}
if (y == 45) {line();}
if (y == 44) {line();}
if (y == 43) {line();}
if (y == 42) {line();}
if (y == 41) {line();}
if (y == 40) {line();}
if (y == 39) {line();}
if (y == 38) {line();}
}
void u_rect(int y) { // O O X O
tft.fillRect(132, y - 1, 30, 1, BLACK);
tft.fillRect(132, y, 30, 6, GREEN);
tft.fillRect(132, y + 6, 30, 1, BLACK);
if (y == 60) {line();}
if (y == 59) {line();}
if (y == 58) {line();}
if (y == 57) {line();}
if (y == 56) {line();}
if (y == 55) {line();}
if (y == 54) {line();}
if (y == 53) {line();}
if (y == 52) {line();}
if (y == 51) {line();}
if (y == 50) {line();}
if (y == 49) {line();}
if (y == 48) {line();}
if (y == 47) {line();}
if (y == 46) {line();}
if (y == 45) {line();}
if (y == 44) {line();}
if (y == 43) {line();}
if (y == 42) {line();}
if (y == 41) {line();}
if (y == 40) {line();}
if (y == 39) {line();}
if (y == 38) {line();}
}
void r_rect(int y) { // O O O X
tft.fillRect(186, y - 1, 30, 1, BLACK);
tft.fillRect(186, y, 30, 6, MAGENTA);
tft.fillRect(186, y + 6, 30, 1, BLACK);
if (y == 60) {line();}
if (y == 59) {line();}
if (y == 58) {line();}
if (y == 57) {line();}
if (y == 56) {line();}
if (y == 55) {line();}
if (y == 54) {line();}
if (y == 53) {line();}
if (y == 52) {line();}
if (y == 51) {line();}
if (y == 50) {line();}
if (y == 49) {line();}
if (y == 48) {line();}
if (y == 47) {line();}
if (y == 46) {line();}
if (y == 45) {line();}
if (y == 44) {line();}
if (y == 43) {line();}
if (y == 42) {line();}
if (y == 41) {line();}
if (y == 40) {line();}
if (y == 39) {line();}
if (y == 38) {line();}
}
//====================== INPUT CAPTURE FUNCTIONS ======================
// blue, red, green, magenta
enum JUDGEMENTS {NONE, MISS, BAD, GREAT, PERFECT} JUDGEMENT;
int readPixelBlue() {
// BLUE = 0x001F = 31
// WHITE = 0xFFFF = 65535
// BLACK = 0x0000 = 0
uint16_t color = BLUE; //BLUE
uint16_t miss3_top = tft.readPixel(39, 44);
uint16_t miss2_top = tft.readPixel(39, 45);
uint16_t miss1_top = tft.readPixel(39, 46);
uint16_t bad_top = tft.readPixel(39, 47);
uint16_t great_top = tft.readPixel(39, 48);
uint16_t perfect_top = tft.readPixel(39, 49);
uint16_t perfect_bot = tft.readPixel(39, 50);
uint16_t great_bot = tft.readPixel(39, 51);
uint16_t bad_bot = tft.readPixel(39, 52);
uint16_t miss1_bot = tft.readPixel(39, 53);
uint16_t miss2_bot = tft.readPixel(39, 54);
uint16_t miss3_bot = tft.readPixel(39, 55);
if (bad_top == color && bad_bot == color) {
return PERFECT;
}
else if (great_top == color && miss1_bot == color && bad_top == BLACK) {
return GREAT;
}
else if (great_bot == color && miss1_top == color && bad_bot == BLACK) {
return GREAT;
}
else if (great_top == color && miss2_top == color && miss3_top == BLACK) {
return BAD;
}
else if (great_bot == color && miss2_bot == color && miss3_bot == BLACK) {
return BAD;
}
else {
return MISS;
}
}
int readPixelRed() {
// RED = 0xF800 = 63488
// WHITE = 0xFFFF = 65535
// BLACK = 0x0000 = 0
uint16_t color = RED;
uint16_t miss3_top = tft.readPixel(93, 44);
uint16_t miss2_top = tft.readPixel(93, 45);
uint16_t miss1_top = tft.readPixel(93, 46);
uint16_t bad_top = tft.readPixel(93, 47);
uint16_t great_top = tft.readPixel(93, 48);
uint16_t perfect_top = tft.readPixel(93, 49);
uint16_t perfect_bot = tft.readPixel(93, 50);
uint16_t great_bot = tft.readPixel(93, 51);
uint16_t bad_bot = tft.readPixel(93, 52);
uint16_t miss1_bot = tft.readPixel(93, 53);
uint16_t miss2_bot = tft.readPixel(93, 54);
uint16_t miss3_bot = tft.readPixel(93, 55);
if (bad_top == color && bad_bot == color) {
return PERFECT;
}
else if (great_top == color && miss1_bot == color && bad_top == BLACK) {
return GREAT;
}
else if (great_bot == color && miss1_top == color && bad_bot == BLACK) {
return GREAT;
}
else if (great_top == color && miss2_top == color && miss3_top == BLACK) {
return BAD;
}
else if (great_bot == color && miss2_bot == color && miss3_bot == BLACK) {
return BAD;
}
else {
return MISS;
}
}
int readPixelGreen() {
// GREEN = 0x07E0 = 2016
// WHITE = 0xFFFF = 65535
// BLACK = 0x0000 = 0
uint16_t color = GREEN;
uint16_t miss3_top = tft.readPixel(147, 44);
uint16_t miss2_top = tft.readPixel(147, 45);
uint16_t miss1_top = tft.readPixel(147, 46);
uint16_t bad_top = tft.readPixel(147, 47);
uint16_t great_top = tft.readPixel(147, 48);
uint16_t perfect_top = tft.readPixel(147, 49);
uint16_t perfect_bot = tft.readPixel(147, 50);
uint16_t great_bot = tft.readPixel(147, 51);
uint16_t bad_bot = tft.readPixel(147, 52);
uint16_t miss1_bot = tft.readPixel(147, 53);
uint16_t miss2_bot = tft.readPixel(147, 54);
uint16_t miss3_bot = tft.readPixel(147, 55);
if (bad_top == color && bad_bot == color) {
return PERFECT;
}
else if (great_top == color && miss1_bot == color && bad_top == BLACK) {
return GREAT;
}
else if (great_bot == color && miss1_top == color && bad_bot == BLACK) {
return GREAT;
}
else if (great_top == color && miss2_top == color && miss3_top == BLACK) {
return BAD;
}
else if (great_bot == color && miss2_bot == color && miss3_bot == BLACK) {
return BAD;
}
else {
return MISS;
}
}
int readPixelMagenta() {
// MAGENTA = 0xF81F = 63519
// WHITE = 0xFFFF = 65535
// BLACK = 0x0000 = 0
uint16_t color = MAGENTA;
uint16_t miss3_top = tft.readPixel(201, 44);
uint16_t miss2_top = tft.readPixel(201, 45);
uint16_t miss1_top = tft.readPixel(201, 46);
uint16_t bad_top = tft.readPixel(201, 47);
uint16_t great_top = tft.readPixel(201, 48);
uint16_t perfect_top = tft.readPixel(201, 49);
uint16_t perfect_bot = tft.readPixel(201, 50);
uint16_t great_bot = tft.readPixel(201, 51);
uint16_t bad_bot = tft.readPixel(201, 52);
uint16_t miss1_bot = tft.readPixel(201, 53);
uint16_t miss2_bot = tft.readPixel(201, 54);
uint16_t miss3_bot = tft.readPixel(201, 55);
if (bad_top == color && bad_bot == color) {
return PERFECT;
}
else if (great_top == color && miss1_bot == color && bad_top == BLACK) {
return GREAT;
}
else if (great_bot == color && miss1_top == color && bad_bot == BLACK) {
return GREAT;
}
else if (great_top == color && miss2_top == color && miss3_top == BLACK) {
return BAD;
}
else if (great_bot == color && miss2_bot == color && miss3_bot == BLACK) {
return BAD;
}
else {
return MISS;
}
}
//====================== SPI INTERRUPT ROUTINE ======================
ISR (SPI_STC_vect) // SPI interrupt routine
{
byte c = SPDR; // read byte from SPI Data Register
if (indx < sizeof(buff)) {
buff[indx++] = c; // save data in the next index in the array buff
if (c == '\n') {
buff[indx - 1] = 0; // replace newline ('\n') with end of string (0)
process = true;
}
}
}
//====================== SPI SM ======================
//continuously print buff and assign message to correspondiing buttons presses from K64F
int SPISM_Tick(int state) {
if (process) {
process = false; //reset the process
//Serial.println(buff); //print the array on serial monitor
indx=0; //reset button to zero
}
if (buff[0] == '1') {
//Serial.println("ARDUINO L");
l = true;
}
else {
l = false;
}
if (buff[1] == '1') {
//Serial.println("ARDUINO D");
d = true;
}
else {
d = false;
}
if (buff[2] == '1') {
//Serial.println("ARDUINO U");
u = true;
}
else {
u = false;
}
if (buff[3] == '1') {
//Serial.println("ARDUINO R");
r = true;
}
else {
r = false;
}
if (buff[4] == '1') {
//Serial.println("ARDUINO START");
start = true;
}
else {
start = false;
}
return 0;
}
//====================== START GAME SM ======================
//look for start btn press to start game
enum START_GAME_SM_STATES {SG_START, SG_GAME_OFF, SG_GAME_ON, SG_ENDGAME_DISPLAY} START_GAME_SM_STATE;
int StartGameSM_Tick(int state) {
//get inputs
//bool start = (digitalRead(start_btn) == LOW);
static unsigned char flash = 0;
//transition
switch(state) {
case SG_START:
state = SG_GAME_OFF;
game_on = false;
start_endgame = false;
//Print start menu
lcd1.setCursor(0,0);
lcd1.print("BOP BOP UPRISING");
lcd1.setCursor(0, 1);
lcd1.print("* * * * * * * *");
lcd2.setCursor(2,0);
lcd2.print("PRESS START");
lcd2.setCursor(4, 1);
lcd2.print("TO PLAY");
tft.fillScreen(BLACK);
tft.setRotation(2);
tft.setTextColor(GREEN);
tft.setTextSize(5);
tft.setCursor(80, 60);
tft.println("BOP");
tft.setTextColor(BLUE);
tft.setCursor(80, 100);
tft.println("BOP");
tft.setTextColor(RED);
tft.setCursor(0, 140);
tft.println("UPRISING");
break;
case SG_GAME_OFF:
if (start) {
state = SG_GAME_ON;
game_on = true;
// Print a message to the LCD1.
lcd1.clear();
lcd1.setCursor(0,0);
lcd1.print("SCOREBOARD");
lcd1.setCursor(0, 1);
lcd1.print("SCORE:");
// Print a message to the LCD2.
lcd2.clear();
lcd2.setCursor(0,0);
lcd2.print("COMBO:100");
lcd2.setCursor(0, 1);
lcd2.print("PERFECT");
tft.setRotation(0);
tft.fillScreen(BLACK);
tft.drawFastHLine(0, 49, 240, WHITE);
tft.drawFastHLine(0, 50, 240, WHITE);
//set score to 0
score = 0;
max_combo = 0;
//current_combo = 0;
//great_combo = 0;
//perfect_combo = 0;
total_miss = 0;
total_bad = 0;
total_great = 0;
total_perfect = 0;
}
else {
state = SG_GAME_OFF;
}
break;
case SG_GAME_ON:
if (end_song && end_scroll) {
state = SG_ENDGAME_DISPLAY;
start_endgame = true;
game_on = false;
// Print a message to the LCD1.
lcd1.clear();
lcd1.setCursor(0,0);
lcd1.print("RESULTS");
lcd1.setCursor(0, 1);
lcd1.print("SCORE:");
lcd1.setCursor(6,0);
lcd1.print(score);
// Print a message to the LCD2.
lcd2.clear();
lcd2.setCursor(0,0);
lcd2.print("MAXCOMBO:");
lcd2.setCursor(0, 1);
lcd2.print(max_combo);
//Print Results on TFT
tft.fillScreen(BLACK);
tft.setRotation(2);
/*
tft.setTextColor(WHITE);
tft.setTextSize(4);
tft.setCursor(40, 10);
tft.println("RESULTS");
tft.setTextSize(2);
tft.setCursor(20, 80);
tft.println("SCORE:");
tft.setCursor(100, 80);
tft.println(score, DEC);
tft.setCursor(20, 110);
tft.println("MAX COMBO:");
tft.setCursor(145, 110);
tft.println(max_combo, DEC);
tft.setTextColor(BLUE);
tft.setCursor(20, 170);
tft.println("PERFECT:");
tft.setCursor(125, 170);
tft.println(total_perfect, DEC);
tft.setTextColor(GREEN);
tft.setCursor(20, 210);
tft.println("GREAT:");
tft.setCursor(100, 210);
tft.println(total_great);
tft.setTextColor(YELLOW);
tft.setCursor(20, 250);
tft.println("BAD:");
tft.setCursor(80, 250);
tft.println(total_bad, DEC);
tft.setTextColor(RED);
tft.setCursor(20, 290);
tft.println("MISS:");
tft.setCursor(90, 290);
tft.println(total_miss, DEC); */
tft.setTextColor(WHITE);
tft.setTextSize(5);
tft.setCursor(60, 120);
tft.println("GAME");
tft.setCursor(60, 160);
tft.println("OVER");
}
else {
state = SG_GAME_ON;
}
break;
case SG_ENDGAME_DISPLAY:
if (end_endgame) {
state = SG_GAME_OFF;
end_game = true;
start_endgame = false;
//reset game
//Print start menu
lcd1.clear();
lcd1.setCursor(0,0);
lcd1.print("BOP BOP UPRISING");
lcd1.setCursor(0, 1);
lcd1.print("* * * * * * * *");
lcd2.clear();
lcd2.setCursor(2,0);
lcd2.print("PRESS START");
lcd2.setCursor(4, 1);
lcd2.print("TO PLAY");
//Print start menu
lcd1.setCursor(0,0);
lcd1.print("BOP BOP UPRISING");
lcd1.setCursor(0, 1);
lcd1.print("* * * * * * * *");
lcd2.setCursor(2,0);
lcd2.print("PRESS START");
lcd2.setCursor(4, 1);
lcd2.print("TO PLAY");
tft.fillScreen(BLACK);
tft.setRotation(2);
tft.setTextColor(GREEN);
tft.setTextSize(5);
tft.setCursor(80, 60);
tft.println("BOP");
tft.setTextColor(BLUE);
tft.setCursor(80, 100);
tft.println("BOP");
tft.setTextColor(RED);
tft.setCursor(0, 140);
tft.println("UPRISING");
unsigned char i;
for (i=0; i<map_sequence_size;i++) {
arrow_position[i] = 320;
}
}
else {
state = SG_ENDGAME_DISPLAY;
}
break;
default:
break;
}
//action
switch(state) {
case SG_GAME_OFF:
//Serial.println("SG GAME OFF");
digitalWrite(game_led_pin, LOW);
digitalWrite(end_display_led_pin, LOW);
if (flash < 8) {
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.setCursor(40, 240);
tft.println("PRESS START BUTTON TO PLAY");
}
else if (flash >= 8 && flash < 16){
tft.fillRect(40, 240, 240, 20, BLACK);
}else {
flash = 0;
}
flash++;
break;
case SG_GAME_ON:
//Serial.println("SG GAME ON");
digitalWrite(game_led_pin, HIGH);
digitalWrite(end_display_led_pin, LOW);
break;
case SG_ENDGAME_DISPLAY:
//Serial.println("SG ENDGAME DISPLAY");
digitalWrite(game_led_pin, LOW);
digitalWrite(end_display_led_pin, HIGH);
break;
default:
break;
}
return state;
}
//====================== MUSIC SYSTEM SM ======================