|
..//main
import processing.io.*;
import g4p_controls.*;
PFont myFont;
int cnt = 0;
int led_buf = 0;
int[] led_box = new int[10];
//int[] led_box = {0,0,0,0,0,0,0,0};
void setup()
{
size(680,800);
smooth();
background(220);
myFont = createFont("한초롬바탕", 32);
textFont(myFont);
textAlign(CENTER, CENTER);
textSize(50);
strokeWeight(6);
stroke(0,0,255);
fill(255,0,0);
text("IoT 전문가 과정", 340, 50);
led_dis(60, 200);
led_init();
createGUI();
}
void draw()
{
// 실습3 카운터
//1. led output
byte_out(cnt);
//2. 화면지움
background(220);
fill(255,0,0);
textSize(50);
text("IoT 전문가 양성과정", 340, 50);
//3. 화면출력
textSize(30);
fill(255,0,0);
text("Up Cnt = " + str(cnt), 100,700);
text("Dn Cnt = " + str(255-cnt), 100,750);
//print("Up Cnt = ");
//println(cnt);
//4. 카운터 값 증가
cnt++;
//5. 카운터값 Max 체크
if(cnt > 255) cnt = 0;
//6. 지연
delay(200);
led_dis(60, 200);
//led_cursor();
led_cnt_dis(60, 200, led_buf);
//print(mouseX);
//print(" ");
//println(mouseY);
}
/*
void mousePressed() {
if (mouseButton == LEFT) {
switch(mouse_cnt)
{
case 1: led_cnt_dis(60, 200, 0x01); break;
} //switch end
} // if end
}
*/
//================================================
// My LIB
// my_R-Pi_Lib
// V1.0 == 2023, 04, 9
final int led1 = 2; // pin 2
final int led2 = 3; // pin 3
final int led3 = 4;
final int led4 = 17;
final int led5 = 27;
final int led6 = 22;
final int led7 = 10;
final int led8 = 9; // pin 9
final int ON = 1;
final int OFF = 0;
final int _0N = 0;
final int _OFF = 1;
final void bit_out(int pin, int value)
{
if(value == 1) GPIO.digitalWrite(pin, GPIO.HIGH);
else GPIO.digitalWrite(pin, GPIO.LOW);
}
final void pin_mode_set(int pin, String value)
{
if(value == "out") GPIO.pinMode(pin, GPIO.OUTPUT);
else if(value == "in") GPIO.pinMode(pin, GPIO.INPUT);
}
void byte_out(int data)
{
bit_out(led1, data%2); // bit 0 = lsb
bit_out(led2, data/2%2); // bit 1
bit_out(led3, data/4%2); // bit 2
bit_out(led4, data/8%2); // bit 3
bit_out(led5, data/16%2); // bit 4
bit_out(led6, data/32%2); // bit 5
bit_out(led7, data/64%2); // bit 6
bit_out(led8, data/128%2); // bit 7 = msb
}
//=========================================================
// gui
/* =========================================================
* ==== WARNING ===
* =========================================================
* The code in this tab has been generated from the GUI form
* designer and care should be taken when editing this file.
* Only add/edit code inside the event handlers i.e. only
* use lines between the matching comment tags. e.g.
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
// It is safe to enter your event code here
} //_CODE_:button1:12356:
* Do not rename this tab!
* =========================================================
*/
public void checkbox1_clicked1(GCheckbox source, GEvent event) { //_CODE_:checkbox1:696418:
println("checkbox1 - GCheckox >> GEvent." + event + " @ " + millis());
//createGUI();
if((led_buf & 0x01) != 0x01){led_buf |= 0x01; led_box[1] = 1;}
else {led_buf &= 0xfe; led_box[1] = 0;}
} //_CODE_:checkbox1:696418:
public void checkbox2_clicked1(GCheckbox source, GEvent event) { //_CODE_:checkbox2:484896:
println("checkbox2 - GCheckbox >> GEvent." + event + " @ " + millis());
//createGUI();
if((led_buf & 0x02) != 0x02) {led_buf |= 0x02; led_box[2] = 1;}
else {led_buf &= 0xfd; led_box[2] = 0;}
} //_CODE_:checkbox2:484896:
public void checkbox3_clicked1(GCheckbox source, GEvent event) { //_CODE_:checkbox3:313654:
println("checkbox3 - GCheckbox >> GEvent." + event + " @ " + millis());
if((led_buf & 0x04) != 0x04) {led_buf |= 0x04; led_box[3] = 1;}
else {led_buf &= 0xfb; led_box[3] = 0;}
} //_CODE_:checkbox3:313654:
public void checkbox4_clicked1(GCheckbox source, GEvent event) { //_CODE_:checkbox4:394795:
println("checkbox4 - GCheckbox >> GEvent." + event + " @ " + millis());
if((led_buf & 0x08) != 0x08) {led_buf |= 0x08; led_box[4] = 1;}
else {led_buf &= 0xf7; led_box[4] = 0;}
} //_CODE_:checkbox4:394795:
public void checkbox5_clicked1(GCheckbox source, GEvent event) { //_CODE_:checkbox5:689745:
println("checkbox5 - GCheckbox >> GEvent." + event + " @ " + millis());
if((led_buf & 0x10) != 0x10) {led_buf |= 0x10; led_box[5] = 1;}
else {led_buf &= 0xef; led_box[5] = 0;}
} //_CODE_:checkbox5:689745:
public void checkbox6_clicked1(GCheckbox source, GEvent event) { //_CODE_:checkbox6:985107:
println("checkbox6 - GCheckbox >> GEvent." + event + " @ " + millis());
if((led_buf & 0x20) != 0x20) {led_buf |= 0x20; led_box[6] = 1;}
else {led_buf &= 0xdf; led_box[6] = 0;}
} //_CODE_:checkbox6:985107:
public void checkbox7_clicked1(GCheckbox source, GEvent event) { //_CODE_:checkbox7:733000:
println("checkbox7 - GCheckbox >> GEvent." + event + " @ " + millis());
if((led_buf & 0x40) != 0x40) {led_buf |= 0x40; led_box[7] = 1;}
else {led_buf &= 0xbf; led_box[7] = 0;}
} //_CODE_:checkbox7:733000:
public void checkbox8_clicked1(GCheckbox source, GEvent event) { //_CODE_:checkbox8:819552:
println("checkbox8 - GCheckbox >> GEvent." + event + " @ " + millis());
if((led_buf & 0x80) != 0x80) {led_buf |= 0x80; led_box[8] = 1;}
else {led_buf &= 0x7f; led_box[8] = 0;}
} //_CODE_:checkbox8:819552:
public void option1_clicked1(GOption source, GEvent event) { //_CODE_:option1:832139:
println("option1 - GOption >> GEvent." + event + " @ " + millis());
//createGUI();
led_buf = 0x01;
//if(led_box[1] == 0) {led_buf |= 0x01; led_box[1] = 1;}
} //_CODE_:option1:832139:
public void option2_clicked1(GOption source, GEvent event) { //_CODE_:option2:515827:
println("option2 - GOption >> GEvent." + event + " @ " + millis());
//createGUI();
led_buf = 0x02;
//if(led_box[2] == 0) {led_buf |= 0x02; led_box[2] = 1;}
} //_CODE_:option2:515827:
public void option3_clicked1(GOption source, GEvent event) { //_CODE_:option3:987687:
println("option3 - GOption >> GEvent." + event + " @ " + millis());
led_buf = 0x04;
//if(led_box[3] == 0) {led_buf |= 0x04; led_box[3] = 1;}
} //_CODE_:option3:987687:
public void option4_clicked1(GOption source, GEvent event) { //_CODE_:option4:943012:
println("option4 - GOption >> GEvent." + event + " @ " + millis());
led_buf = 0x08;
//if(led_box[4] == 0) {led_buf |= 0x08; led_box[4] = 1;}
} //_CODE_:option4:943012:
public void option5_clicked1(GOption source, GEvent event) { //_CODE_:option5:521106:
println("option5 - GOption >> GEvent." + event + " @ " + millis());
led_buf = 0x10;
//if(led_box[5] == 0) {led_buf |= 0x10; led_box[5] = 1;}
} //_CODE_:option5:521106:
public void option6_clicked1(GOption source, GEvent event) { //_CODE_:option6:212433:
println("option6 - GOption >> GEvent." + event + " @ " + millis());
led_buf = 0x20;
//if(led_box[6] == 0) {led_buf |= 0x20; led_box[6] = 1;}
} //_CODE_:option6:212433:
public void option7_clicked1(GOption source, GEvent event) { //_CODE_:option7:848707:
println("option7 - GOption >> GEvent." + event + " @ " + millis());
led_buf = 0x40;
//if(led_box[7] == 0) {led_buf |= 0x40; led_box[7] = 1;}
} //_CODE_:option7:848707:
public void option8_clicked1(GOption source, GEvent event) { //_CODE_:option8:519086:
println("option8 - GOption >> GEvent." + event + " @ " + millis());
led_buf = 0x80;
//if(led_box[8] == 0) {led_buf |= 0x80; led_box[8] = 1;}
} //_CODE_:option8:519086:
// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setMouseOverEnabled(false);
surface.setTitle("Sketch Window");
checkbox1 = new GCheckbox(this, 33, 390, 54, 20);
checkbox1.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
checkbox1.setText("LED1");
checkbox1.setOpaque(false);
checkbox1.addEventHandler(this, "checkbox1_clicked1");
checkbox2 = new GCheckbox(this, 114, 390, 54, 20);
checkbox2.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
checkbox2.setText("LED2");
checkbox2.setOpaque(false);
checkbox2.addEventHandler(this, "checkbox2_clicked1");
checkbox3 = new GCheckbox(this, 194, 390, 54, 20);
checkbox3.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
checkbox3.setText("LED3");
checkbox3.setOpaque(false);
checkbox3.addEventHandler(this, "checkbox3_clicked1");
checkbox4 = new GCheckbox(this, 274, 390, 54, 20);
checkbox4.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
checkbox4.setText("LED4");
checkbox4.setOpaque(false);
checkbox4.addEventHandler(this, "checkbox4_clicked1");
checkbox5 = new GCheckbox(this, 354, 390, 54, 20);
checkbox5.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
checkbox5.setText("LED5");
checkbox5.setOpaque(false);
checkbox5.addEventHandler(this, "checkbox5_clicked1");
checkbox6 = new GCheckbox(this, 434, 390, 54, 20);
checkbox6.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
checkbox6.setText("LED6");
checkbox6.setOpaque(false);
checkbox6.addEventHandler(this, "checkbox6_clicked1");
checkbox7 = new GCheckbox(this, 514, 390, 54, 20);
checkbox7.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
checkbox7.setText("LED7");
checkbox7.setOpaque(false);
checkbox7.addEventHandler(this, "checkbox7_clicked1");
checkbox8 = new GCheckbox(this, 594, 390, 54, 20);
checkbox8.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
checkbox8.setText("LED8");
checkbox8.setOpaque(false);
checkbox8.addEventHandler(this, "checkbox8_clicked1");
togGroup1 = new GToggleGroup();
option1 = new GOption(this, 33, 440, 54, 20);
option1.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
option1.setText("LED1");
option1.setOpaque(false);
option1.addEventHandler(this, "option1_clicked1");
option2 = new GOption(this, 114, 440, 54, 20);
option2.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
option2.setText("LED2");
option2.setOpaque(false);
option2.addEventHandler(this, "option2_clicked1");
option3 = new GOption(this, 194, 440, 54, 20);
option3.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
option3.setText("LED3");
option3.setOpaque(false);
option3.addEventHandler(this, "option3_clicked1");
option4 = new GOption(this, 274, 440, 54, 20);
option4.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
option4.setText("LED4");
option4.setOpaque(false);
option4.addEventHandler(this, "option4_clicked1");
option5 = new GOption(this, 354, 440, 54, 20);
option5.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
option5.setText("LED5");
option5.setOpaque(false);
option5.addEventHandler(this, "option5_clicked1");
option6 = new GOption(this, 434, 440, 54, 20);
option6.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
option6.setText("LED6");
option6.setOpaque(false);
option6.addEventHandler(this, "option6_clicked1");
option7 = new GOption(this, 514, 440, 54, 20);
option7.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
option7.setText("LED7");
option7.setOpaque(false);
option7.addEventHandler(this, "option7_clicked1");
option8 = new GOption(this, 594, 440, 54, 20);
option8.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
option8.setText("LED8");
option8.setOpaque(false);
option8.addEventHandler(this, "option8_clicked1");
togGroup1.addControl(option1);
//option1.setSelected(true);
togGroup1.addControl(option2);
togGroup1.addControl(option3);
togGroup1.addControl(option4);
togGroup1.addControl(option5);
togGroup1.addControl(option6);
togGroup1.addControl(option7);
togGroup1.addControl(option8);
}
// Variable declarations
// autogenerated do not edit
GCheckbox checkbox1;
GCheckbox checkbox2;
GCheckbox checkbox3;
GCheckbox checkbox4;
GCheckbox checkbox5;
GCheckbox checkbox6;
GCheckbox checkbox7;
GCheckbox checkbox8;
GToggleGroup togGroup1;
GOption option1;
GOption option2;
GOption option3;
GOption option4;
GOption option5;
GOption option6;
GOption option7;
GOption option8;
//==================================
// gui_prj
void chk_ds()
{
//checkbox1.selected(false);
}
void led_cnt_dis(int st_x, int st_y, int data)
{
for(; st_x <= 650;)
{
if((data & 0x01) == 0x01) fill(255, 0,0);
else fill(#EFF707);
ellipse(st_x, 200, 60, 60);
rect(st_x-30, st_y+70, 60,80);
data >>= 1;
st_x += 80;
} // for end
}
void led_cursor()
{
if((mouseY > 168) && (mouseY < 229))
{
if((mouseX > 30) && (mouseX < 647)) cursor(HAND);
}
else cursor(MOVE);
}
void led_dis_old()
{
int buf;
for(int k=60; k <= 650;)
{
buf = (k/80)+1;
switch(buf)
{
case 1:
if((cnt & 0x01) == 0x01) fill(255, 0,0);
else fill(#EFF707);
ellipse(k, 200, 60, 60);
break;
case 2:
if((cnt & 0x02) == 0x02) fill(255, 0,0);
else fill(#EFF707);
ellipse(k, 200, 60, 60);
break;
case 3:
if((cnt & 0x04) == 0x04) fill(255, 0,0);
else fill(#EFF707);
ellipse(k, 200, 60, 60);
break;
case 4:
if((cnt & 0x08) == 0x08) fill(255, 0,0);
else fill(#EFF707);
ellipse(k, 200, 60, 60);
break;
case 5:
if((cnt & 0x10) == 0x10) fill(255, 0,0);
else fill(#EFF707);
ellipse(k, 200, 60, 60);
break;
case 6:
if((cnt & 0x20) == 0x20) fill(255, 0,0);
else fill(#EFF707);
ellipse(k, 200, 60, 60);
break;
case 7:
if((cnt & 0x40) == 0x40) fill(255, 0,0);
else fill(#EFF707);
ellipse(k, 200, 60, 60);
break;
case 8:
if((cnt & 0x80) == 0x80);
else fill(#EFF707);
ellipse(k, 200, 60, 60);
break;
} // switch
//if((data & 0x01) == 0x01) fill(255, 0,0);
//else fill(#EFF707);
//ellipse(k, 200, 60, 60);
//data >>= 1;
k += 80;
} // for end
}
void led_init()
{
GPIO.pinMode(led1, GPIO.OUTPUT); // 출력으로 선언
pin_mode_set(3, "out");
GPIO.pinMode(led3, GPIO.OUTPUT);
GPIO.pinMode(17, GPIO.OUTPUT);
GPIO.pinMode(27, GPIO.OUTPUT); // 출력으로 선언
GPIO.pinMode(22, GPIO.OUTPUT);
GPIO.pinMode(10, GPIO.OUTPUT);
pin_mode_set(led8, "out");
// init = all off
GPIO.digitalWrite(led1, GPIO.HIGH);
GPIO.digitalWrite(3, GPIO.HIGH);
GPIO.digitalWrite(led3, GPIO.HIGH);
GPIO.digitalWrite(17, GPIO.HIGH);
GPIO.digitalWrite(led5, GPIO.HIGH);
GPIO.digitalWrite(22, GPIO.HIGH);
GPIO.digitalWrite(10, GPIO.HIGH);
GPIO.digitalWrite(led8, GPIO.HIGH);
}
void led_dis(int st_x, int st_y)
{
textSize(20);
cursor(ARROW);
fill(#03FF3B);
rect(st_x-40, st_y+60, 640, 100);
for(; st_x <= 650;)
{
fill(0);
text("LED" + str((st_x/80) + 1), st_x-1, 150); // org k-23
fill(#EFF707);
ellipse(st_x, st_y, 60, 60); //60, 200, 60,60
rect(st_x-30, st_y+70, 60,80);
st_x += 80;
}
}
|