~画面のボタンを押したらLED点灯~
画面のボタンを押すと、スクーミーボードのLEDが消えます!
目次
int ledPin = 10;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
if(Serial.available() > 0){
char val = Serial.read();
if(val == 'h'){
digitalWrite(ledPin, HIGH);
}else if(val == 'l'){
digitalWrite(ledPin, LOW);
}
}
}
add_library('serial')
myPort = None
available_serialport = 2
arduinoPort = Serial.list()[available_serialport]
sensingValue = 0
class PBtn:
def __init__(self, xpos, ypos, wb, hb):
self.x = xpos
self.y = ypos
self.w = wb
self.h = hb
def display(self, stat):
if stat == 0:
col_top = 230
col_right = 100
col_bottom = 80
col_left = 210
else:
col_top = 80
col_right = 210
col_bottom = 230
col_left = 100
fill(255, 255, 0)
rect(self.x, self.y, self.w, self.h)
fill(col_top)
quad(self.x - 10, self.y - 10, self.x + self.w + 10, self.y - 10,
self.x + self.w, self.y, self.x, self.y)
fill(col_right)
quad(self.x + self.w, self.y, self.x + self.w + 10, self.y - 10,
self.x + self.w + 10, self.y + self.h + 10, self.x + self.w, self.y + self.h)
fill(col_bottom)
quad(self.x, self.y + self.h, self.x + self.w, self.y + self.h, self.x + self.w + 10, self.y + self.h + 10, self.x - 10, self.y + self.h + 10)
fill(col_left)
quad(self.x - 10, self.y - 10, self.x, self.y, self.x, self.y + self.h, self.x - 10, self.y + self.h + 10)
textSize(24)
fill(0)
text("PUSH", self.x + 15, self.y + self.h + 60)
text("LED OFF", self.x, self.y + self.h + 80)
def areachk(self):
if mouseX > self.x and mouseX < self.x + self.w and mouseY > self.y and mouseY < self.y + self.h:
return 1
else:
return 0
btn = PBtn(50, 50, 100, 50)
def setup():
global myPort
size(200, 200)
noStroke()
frameRate(10)
myPort = Serial(this, arduinoPort, 9600)
btn.display(0)
def draw():
pass
def mousePressed():
if btn.areachk() == 1:
btn.display(1)
myPort.write('h')
def mouseReleased():
if btn.areachk() == 1:
btn.display(0)
myPort.write('l')
キャロット
このページのHelloNoは、050014です!