วันอังคารที่ 12 กุมภาพันธ์ พ.ศ. 2562


งานที่17


ปฏิบัติงานที่17 Codeโปรแกรมงาน #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int PIRpin = 8; void setup() { lcd.begin(); pinMode(PIRpin,INPUT); lcd.home(); lcd.print("Waiting for PIR"); delay(10000); lcd.clear(); } void loop() { int x = digitalRead(PIRpin); lcd.home(); lcd.print("PIR = "); lcd.print(x); delay(100); }





งานที่16


ปฏิบัติงานที่16 Codeโปรแกรมงาน #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int PIRpin = 8; void setup() { lcd.begin(); pinMode(PIRpin,INPUT); lcd.home(); lcd.print("Waiting for PIR"); delay(10000); lcd.clear(); } void loop() { int x = digitalRead(PIRpin); lcd.home(); lcd.print("PIR = "); lcd.print(x); delay(100); }





งานที่15


ปฏิบัติงานที่15 Codeโปรแกรมงาน #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int triggerPin = 13; int echoPin = 12; long duration,distCM,temp_distCM=0; void setup() { lcd.begin(); lcd.setCursor(0,0); lcd.print("Dist = cm"); pinMode(triggerPin,OUTPUT); pinMode(echoPin,INPUT); } void loop() { digitalWrite(triggerPin,LOW); delayMicroseconds(2); digitalWrite(triggerPin,HIGH); delayMicroseconds(10); digitalWrite(triggerPin,LOW); duration = pulseIn(echoPin,HIGH); distCM = duration/58; if (temp_distCM != distCM) { lcd.setCursor(7,0); lcd.print(" "); } lcd.setCursor(7,0); lcd.print(distCM); temp_distCM = distCM; delay(300); }





งานที่14


ปฏิบัติงานที่14 Codeโปรแกรมงาน #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int aval,temp_aval=0; void setup() { lcd.begin(); lcd.setCursor(0,0); lcd.print("aval = "); } void loop() { aval = analogRead(A0); if (temp_aval != aval) { lcd.setCursor(7,0); lcd.print(" "); } lcd.setCursor(7,0); lcd.print(aval); temp_aval = aval; delay(300); }





งานที่13


ปฏิบัติงานที่13 Codeโปรแกรมงาน #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int aVal=0,tempaVal=0; void setup() { lcd.begin(); } void loop() { aVal = analogRead(A0); if (tempaVal != aVal) { lcd.clear(); lcd.setCursor(0,0); lcd.print("LDR"); lcd.setCursor(0,1); lcd.print(aVal); delay(300); } tempaVal = aVal; }





งานที่12


ปฏิบัติงานที่12 Codeโปรแกรมงาน #include "LedControl.h" #include "Keypad.h" #define C4 262 #define D4 294 #define E4 330 #define F4 349 #define G4 392 #define A4 440 #define B4 494 #define C5 523 char keys[4][4]={ {7,8,9,0}, {4,5,6,0}, {1,2,3,0}, {0,0,0,0}}; byte rowPins[] = {7,6,5,4}; byte colPins[] = {3,2,1,0}; Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4); int melody[] = {C4,D4,E4,F4,G4,A4,B4,C5}; int dl = 300; int buzzerpin = 11; LedControl lc=LedControl(8,10,9,1); // Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices void setup() { lc.shutdown(0,false); lc.setIntensity(0,5); lc.clearDisplay(0); pinMode(buzzerpin,OUTPUT); digitalWrite(buzzerpin,HIGH); } void loop() { char key = keypad.getKey(); if ((key != NO_KEY) && (key < 9)) { lc.setDigit(0,0,key,false); tone(buzzerpin, melody[key-1],dl); delay(dl); digitalWrite(buzzerpin,HIGH); } }






งานที่11


ปฏิบัติงานที่11
Codeโปรแกรมงาน
#include "LedControl.h"
#define C4 262 #define D4 294
#define G4 392
#define E4 330 #define F4 349 #define A4 440
int melody[] = {C4,D4,E4,F4,G4,A4,B4,C5};
#define B4 494 #define C5 523
int timestop = 70;
float beats[] ={1,1,1,1,1,1,1,1}; int buzzerpin = 11;
// Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices
LedControl lc=LedControl(8,10,9,1); void setup() { lc.shutdown(0,false);
pinMode(buzzerpin,OUTPUT);
lc.setIntensity(0,5); lc.clearDisplay(0); int dl = 500; int numnote;
tone(buzzerpin, melody[i],dl*beats[i]);
numnote = sizeof(melody)/2; for (int i=0;i<numnote;i++) { lc.setChar(0,7-i,'-',false);
}
delay(dl*beats[i]); digitalWrite(buzzerpin,HIGH); delay(timestop); } } void loop()
{





งานที่10

ปฏิบัติงานที่10 Codeโปรแกรมงาน #include "LedControl.h" #include "Keypad.h" char keys[4][4]={ {'7','8','9','A'}, {'4','5','6','B'}, {'1','2','3','C'}, {'E','0','F','D'}}; byte rowPins[] = {7,6,5,4}; byte colPins[] = {3,2,1,0}; Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4); LedControl lc=LedControl(8,10,9,1); // Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices void setup() { lc.shutdown(0,false); lc.setIntensity(0,5); lc.clearDisplay(0); } void loop() { char key = keypad.getKey(); if (key != NO_KEY) { lc.setChar(0,0,key,false); } }





 

งานที่9


ปฏิบัติงานที่ 9 Codeโปรแกรมงาน int led = 13; int sw = 2; void setup() { Serial.begin(9600); pinMode(led,OUTPUT); pinMode(sw,INPUT); } void loop() { int x; x = digitalRead(sw); Serial.print("x = ");Serial.println(x); digitalWrite(led,!x); }




วันพุธที่ 6 กุมภาพันธ์ พ.ศ. 2562

                                                                        งานที่7


                                    

               
         อธิบาย  ต่อARDUINOไปต่อกับU1และต่อโดย7SEGทำให้เลขขึ้นที่ตัวของ7SEG

     #include <LiquidCrysal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
void setup(){
  pinMode(0,INPUT);
  pinMode(1,INPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  lcd.begin(16,2);
}
void loop(){
  int x=digitaread(0);
  int y=digitaread(1);
  if(x==0)
{
  digitalwrite(8,HIGH);
  lcd.setCursor(0,1);
  lcd.print("button 1 ");
  digitalwrite(8,LOW);
}
  if(y==0)
{
  digitalwrite(9,HIGH)
  lcd.setCursor(0,1);
  lcd.print("button 2 ")
  digitalwrite(9,LOW);
}
}
งานที่6

 

    อธิบาย  เป็นการต่อไฟไปสวิตช์และต่ออกับLCDให้ตัวเลขขึ้นบนLCDและต่อมอเตอร์2ตัวให้มอเตอร์ทำงานโดยมอเตอร์ต่อกาวสวิตช์ต่อไฟแล้วใส่โคตไปที่ตัวARDUION
     
  #include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);

void setup() {

  pinMode(0, INPUT); //
  pinMode(1, INPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  lcd.begin(16,2);
}


void loop() {
  int x=digitalRead(0);
  int y=digitalRead(1);
  if(x==0)
 { digitalWrite(8, HIGH);
  delay(300); 
  lcd.setCursor(0,1);
  lcd.print("Left");               
  digitalWrite(8, LOW);                     
}
if(y==0)
{ digitalWrite(9, HIGH);
  delay(300);
  lcd.setCursor(0,1);
  lcd.print ("Right");
  digitalWrite(9,LOW);
}
}
C:\Users\PHICHI~1\AppData\Local\Temp\arduino_build_112323/Blink10.ino.hex