วันอาทิตย์ที่ 9 ธันวาคม พ.ศ. 2561

งานที่ 11 ตัวอย่างงานที่ใช้โปรแกรม Arduino สปที่ 11

ตัวอย่างงานที่ใช้โปรแกรม Arduino


การเขียนโปรแกรมเบื้องต้นกับ Arduino C++ (การรับค่าสัญญาณ Analog)



ตัวอย่าง Code
// select the input pin for the potentiometer
int sensorPin = A3;
 
// select the pin for the LED
int ledPin = 13;
 
// variable from the sensor
int sensorValue = 0;
 
void setup() {
   // declare the ledPin as an OUTPUT:
   pinMode(ledPin, OUTPUT);
   Serial.begin(9600);
}
 
void loop() {
   // read the value from the sensor:
   sensorValue = analogRead(sensorPin);
   //print report:
   Serial.println(sensorValue);
   //call Blinky LED
   Blinky(sensorValue);
}
 
void Blinky(int time) {
   digitalWrite(ledPin, HIGH);
   delay(time);
   digitalWrite(ledPin, LOW);
   delay(time);
}
อ้างอิง : http://www.myarduino.net/article/24/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99%E0%B8%81%E0%B8%B1%E0%B8%9A-arduino-c-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%84%E0%B9%88%E0%B8%B2%E0%B8%AA%E0%B8%B1%E0%B8%8D%E0%B8%8D%E0%B8%B2%E0%B8%93-analog

งานที่ 10 ตัวอย่างงานที่ใช้โปรแกรม Arduino สปที่ 10

ตัวอย่างงานที่ใช้โปรแกรม Arduino

การเขียนโปรแกรมเบื้องต้นกับ Arduino C++ (การรับค่าจากสวิตซ์)


Code( ถ้ากดปุ่ม  LED จะดับ)
 int buttonPin = 2;     // the number of the pushbutton pin
 int ledPin =  9;      // the number of the LED pin
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
void setup() {
  // initialize the LED pin as an output:
Serial.begin(9600);
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}
void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
Serial.println("turn LED on");
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
Serial.println("turn LED off");
    digitalWrite(ledPin, LOW); 
  }
}
อ้างอิง http://www.myarduino.net/article/8/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99%E0%B8%81%E0%B8%B1%E0%B8%9A-arduino-c-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%84%E0%B9%88%E0%B8%B2%E0%B8%88%E0%B8%B2%E0%B8%81%E0%B8%AA%E0%B8%A7%E0%B8%B4%E0%B8%95%E0%B8%8B%E0%B9%8C

งานที่ 9 ตัวอย่างงานที่ใช้โปรแกรม Arduino สปที่ 9

ตัวอย่างงานที่ใช้โปรแกรม Arduino

การเขียนโปรแกรมเบื้องต้นกับ Arduino C++ (ไฟวิ่ง)


int led1 = 2; // กำหนดขาใช้งาน 
int led2 = 3; 
int led3 = 4; 
int led4 = 5; 
void setup() 
{ 
pinMode(led1, OUTPUT); // กำหนดขาทำหน้าที่ OUTPUT 
pinMode(led2, OUTPUT); 
pinMode(led3, OUTPUT); 
pinMode(led4, OUTPUT); 
} 
void loop() 
{ 
digitalWrite(led1,HIGH); // ไฟ LED 1 ติด 500 ms 
delay(500); 
digitalWrite(led1,LOW); // ไฟ LED 1 ดับ500 ms 
delay(500); 
digitalWrite(led2,HIGH); 
delay(500); 
digitalWrite(led2,LOW); 
delay(500); 
digitalWrite(led3,HIGH); 
delay(500); 
digitalWrite(led3,LOW); 
delay(500); 
digitalWrite(led4,HIGH); 
delay(500); 
digitalWrite(led4,LOW); 
delay(500); 
} 
อ้างอิง http://www.myarduino.net/article/6/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99%E0%B8%81%E0%B8%B1%E0%B8%9A-arduino-c-%E0%B9%84%E0%B8%9F%E0%B8%A7%E0%B8%B4%E0%B9%88%E0%B8%87

งานที่ 8 ตัวอย่างงานที่ใช้โปรแกรม Arduino สปที่ 8

ตัวอย่างงานที่ใช้โปรแกรม Arduino

การเขียนโปรแกรมเบื้องต้นกับ Arduino C++ (การรับค่าจากสวิตซ์)



Code( ถ้ากดปุ่ม  LED จะดับ)
 int buttonPin = 2;     // the number of the pushbutton pin
 int ledPin =  9;      // the number of the LED pin
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
void setup() {
  // initialize the LED pin as an output:
Serial.begin(9600);
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}
void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
Serial.println("turn LED on");
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
Serial.println("turn LED off");
    digitalWrite(ledPin, LOW); 
  }
}
อ้างอิง http://www.myarduino.net/article/8/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99%E0%B8%81%E0%B8%B1%E0%B8%9A-arduino-c-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%84%E0%B9%88%E0%B8%B2%E0%B8%88%E0%B8%B2%E0%B8%81%E0%B8%AA%E0%B8%A7%E0%B8%B4%E0%B8%95%E0%B8%8B%E0%B9%8C

งานที่ 7 ตัวอย่างงานที่ใช้โปรแกรม Arduino สปที่ 7

ตัวอย่างงานที่ใช้โปรแกรม Arduino


สอนใช้งาน Arduino Wi-Fi Module ESP8266 แบบ TCP Client 

void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second

}
อ้างอิง : http://www.myarduino.net/article/49/%E0%B8%AA%E0%B8%AD%E0%B8%99%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-arduino-wi-fi-module-esp8266-%E0%B9%81%E0%B8%9A%E0%B8%9A-tcp-client