ส่วนประกอบงานวิชา การเขียนโปรแกรมคอมฯ ครั้งที่ 1

 ใบรายงานผลการปฏิบัติงาน

Code


int motorpin =2;
void setup() {
pinMode(motorpin,OUTPUT);
Serial.begin(9600);
while(! Serial);
Serial.println ("Speed 0 to 255");
             }

void loop(){

if(Serial.available())
{
  int speed = Serial.parseInt();
  if(speed >=0 && speed <=255)
{
analogWrite(motorpin,speed);
}         
}
 }
ภาพจำลองการทำงานด้วยโปรแกรม Proteus

อธิบายการทำงานของโปรแกรม
ไฟ LED กระพริบทุก 1วิ และจะกระพริบตลอดถ้าหากเรายังป้อนไฟใส่อดูโน่
และมีตัว. r  ใส่ไว้ไห้ด้วย

ความคิดเห็น

บทความที่ได้รับความนิยม