top of page
    กลุ่ม Treadmill วันนี้ช่วงเช้าพวกผมได้ศึกษาเกี่ยวกับการเขียน Array และหัดเขียน code แบบ Array แต่ก็ยังไม่เข้าใจ ช่วงบายพวกผมได้มาศึกษาเพิมเติมจนเข้าใจ และได้ลองเขียน code อีกรอบแล้วรอบนี้ก็เขียนเสร็จและรันผ่าน  ต่อมาพวกผมได้เพิ่มคำสั่งคีย์บอดเพื่อแปลงค่าจากสวิตว์ให้เป็นคีย์บอด
ตัวอย่าง code

#include <Keyboard.h>
int sen[] = {2,3,4,5,6,7};
unsigned long Time[6]={0,0,0,0,0,0};

void setup() {
  Serial.begin(9600);
  Keyboard.begin();
  pinMode(sen,INPUT);

}

void loop() {
  int sensor[6] = {digitalRead(sen[0]),digitalRead(sen[1]),digitalRead(sen[2]),digitalRead(sen[3]),digitalRead(sen[4]),digitalRead(sen[5])};

  if(sensor[0] == LOW){
    Time[0] = millis();
  }
  else if(sensor[1] == LOW){
    Time[1] = millis();
  }
  else if(sensor[2] == LOW){
    Time[2] = millis();
  }
  
  if(Time[0]<Time[1]&&Time[1]<Time[2]){
    Keyboard.press('w');
    delay(20);
  }
  else if(Time[0]<Time[1]){
    Keyboard.press('w');
    delay(20);
  }
  else if(Time[1]<Time[2]){
    Keyboard.press('w');
    delay(20);
  }
  else {
    Keyboard.releaseAll();
  }
}
เว็บไซต์ที่ศึกษา  https://www.ioxhop.com/article/7/arduino-ตอนที่-6-ตัวแปร-และอาเรย์

                                                                                                               กฤษดา  ชัยเนตร

กลุ่ม Robot Arm  หลังจากที่ได้ไปซื้อ Dc Motor มาแล้ว ก็ได้ทำการเขียนโปรแกรมควบคุมการทำงาน โดยให้หยุดตามตำแหน่งที่ Encoder อ่านค่าได้ตามที่เรากำหนด 
Code ที่ใช้ทำการทดสอบ
#define outputA 3
 #define outputB 2
 int counter = 0; 
 int aState;
 int aLastState;  
 int In1 = 4;
int In2 = 5;
int ENA = 6;
int SPEED = 255;
 void setup() { 
   pinMode (outputA,INPUT);
   pinMode (outputB,INPUT);
   pinMode(In1,OUTPUT);
pinMode(In2,OUTPUT);
pinMode(ENA,OUTPUT);
digitalWrite(In1,HIGH);
digitalWrite(In2,LOW);
analogWrite(ENA,255);
   
   Serial.begin (9600);
   // Reads the initial state of the outputA
   aLastState = digitalRead(outputA);   
 } 
 void loop() { 
   aState = digitalRead(outputA); ifferent, that means a Pulse has occured
   if (aState != aLastState){     
    
     if (digitalRead(outputB) != aState) { 
       counter ++;
     } else {
       counter --;
     }
     if(counter == 150){
      digitalWrite(In1,LOW);
      digitalWrite(In2,LOW);
     }
     Serial.print("Position: ");
     Serial.println(counter);
   } 
   aLastState = aState; 

                                                                                                                เจษฎา   ทองภาพ
bottom of page