You are on page 1of 2

INPUT

DIGITAL

int ledPin = 13; // LED connected to digital pin 13


int inPin = 7;
// pushbutton connected to digital pin 7
int val = 0;
// variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(inPin, INPUT);
}
void loop()
{
val = digitalRead(inPin);
digitalWrite(ledPin, val);
value
}

OUTPUT

// sets the digital pin 13 as output


// sets the digital pin 7 as input

// read the input pin


// sets the LED to the button's

DIGITAL

int ledPin = 13;


pin 13
void setup()
{
pinMode(ledPin, OUTPUT);
output
}
void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}

// LED connected to digital

// sets the digital pin as

//
//
//
//

sets the LED on


waits for a second
sets the LED off
waits for a second

INPUT

ANALOG

int sensorPin = A0;


potentiometer
int ledPin = 13;
int sensorValue = 0;
from the sensor

// select the input pin for the


// select the pin for the LED
// variable to store the value coming

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

OUTPUT

ANALOG

int ledPin = 9;
int analogPin = 3;
3
int val = 0;

// LED connected to digital pin 9


// potentiometer connected to analog pin
// variable to store the read value

void setup()
{
pinMode(ledPin, OUTPUT);
}

// sets the pin as output

void loop()
{
val = analogRead(analogPin);
// read the input pin
analogWrite(ledPin, val / 4); // analogRead values go from
0 to 1023, analogWrite values from 0 to 255
}

You might also like