รับค่าจากสวิตซ์ By Kornkanok

การรับค่าจากสวิตซ์

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);

}

}

 

ไฟล์ Source Code

https://drive.google.com/a/bumail.net/file/d/0B0jje0eyOqhKckVOV1hNZmtIWU0/view?usp=sharing

KORNKANOK SARANAN
at GlurGeek.Com

Leave a Reply

© 2022 GlurGeek.Com