Digital I/O - Sketch Programming - Arduino Development for OSX and iOS (2015)

Arduino Development for OSX and iOS (2015)

2. Sketch Programming

2.5 Digital I/O

In this section, we try to build Arduino program by utilizing digital I/O. We can write digital data using digitalWrite(). To read digital input, you can use digitalRead().

To implement our demo, you need a pushbutton and a LED. Connect LED to Arduino digital pin 8. You also attach a pushbutton on Arduino digital pin 6.

Open Arduino software and write this code.

int led = 8;

int pushButton =6;

int state = 0;

void setup() {

pinMode(led, OUTPUT);

pinMode(pushButton, INPUT);

}

void loop() {

state = digitalRead(pushButton);

digitalWrite(led,state);

delay(300);

}

Save this code, called ButtonLed.ino.

Compile and upload the program. After that, press pushbutton so you should lighting LED.

chp2-8





All materials on the site are licensed Creative Commons Attribution-Sharealike 3.0 Unported CC BY-SA 3.0 & GNU Free Documentation License (GFDL)

If you are the copyright holder of any material contained on our site and intend to remove it, please contact our site administrator for approval.

© 2016-2026 All site design rights belong to S.Y.A.