-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFM_Radio_Processing.pde
136 lines (127 loc) · 2.51 KB
/
FM_Radio_Processing.pde
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
import processing.serial.*;
PFont f;
PImage img;
PGraphics ico;
int u = 5;
int d = 7;
int c = 8;
int x = 1;
int reg;
String [] Char = {
".", " ", "1"
};
String [] Num = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
};
Serial myPort;
//--------------------------------------------------
void setup() {
size(200, 200);
smooth(255);
println(myPort.list());
myPort = new Serial(this, Serial.list()[0/*Change for Arduino Port*/], 9600); //Setup Arduino SerialPort
f = createFont("Arial", 32, true);
img = loadImage("radio.png");
ico = createGraphics(16, 16, JAVA2D);
frame.setTitle("FM radio v1.0");
ico.beginDraw();
ico.image(img, 0, 0, 20, 20);
ico.endDraw();
frame.setIconImage(ico.image);
}
//------------------------------------------------
void draw() {
background(0);
fill(0, 255, 0);
textFont(f);
text(Char[x], 20, 100);
text(Num[c], 40, 100);
text(Num[d], 60, 100);
text(Char[0], 80, 100);
text(Num[u], 90, 100);
text("FM", 110, 100);
fill(255, 0, 0);
rectMode(CENTER);
rect(30, 180, 20, 20);
rect(170, 180, 20, 20);
//------------------------------------------------
}
void mousePressed() {
if (mouseX > 10 && mouseX < 50) {
if (mouseY > 150 && mouseY < 190) {
myPort.write(48);
}
}
if (mouseX > 150 && mouseX < 190) {
if (mouseY > 150 && mouseY < 190) {
myPort.write(49);
}
}
}
//--------------------------------------------
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
myPort.write(48);
}
}
/*if (key == CODED) {*/
if (keyCode == RIGHT) {
myPort.write(49);
// }
}
}
//--------------------------------------------
void serialEvent(Serial myPort) {
reg = myPort.read();
println(reg);
if (reg == 48) {
u --;
if (u<0) {
d --;
u =9;
if (d<0) {
c--;
d =9;
if (c<0) {
c = 9;
x = 1;
}
}
}
if (u == 4 && d == 7 && c == 8) {
u =9;
d =7;
c =0;
x =2;
myPort.write(50);
}
}
else if ( reg == 49) {
u ++;
if (u>9) {
d ++;
u =0;
if (d>9) {
c++;
d =0;
if (c>9) {
c = 0;
x = 2;
}
}
}
if (u == 0 && d == 8 && c == 0 && x == 2) {
u =5;
d =7;
c =8;
x =1;
myPort.write(51);
}
}
}
/*-------------------------------
| |
| END :) |
| |
--------------------------------*/