Arduino Worksheet: Analogwrite (5,255)
Arduino Worksheet: Analogwrite (5,255)
Arduino Worksheet: Analogwrite (5,255)
Write the command line which sets 5th digital pin to Logic 1.
AnalogWrite (5,255);
// or
AnalogWrite (5,HIGH);
40mA
Write the command line which indicates 9th pin will be used to write.
pinMode (9,OUTPUT);
Write the command line which lits the LED connected to 5th pin.
Digitalwrite (5,HIGH);
int sensorPin = 0;
int ledPin = 13;
int sensorValue = 0;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop()
{
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
}
The amount of time the LED will be on and off depends on the value obtained from analog input.
Write the command line which lits the LED connected 8th pin if variable X is less than 15 and lits
LED connected 7th pin if variable X is greater or equal 15.
If (sayi<15) digitalWrite(8,HIGH); else digitalWrite(7,HIGH);
Write the command line which defines seven LEDs connected to pins 4,5,6,7,8,9,10 in array
structure.
int ledpins[]={4,5,6,7,8,9,10};
Write the command line which unlits eight LEDs by one by starting from the end
for (int i=7; i>=0; i--) digitalWrite(ledpins[i],LOW);
Write the command line which generates a random number and lits the LED connected 3rd pin if
number is even, otherwise unlits LED connected 3rd pin
number=random();
if (number%2 == 0) digitalWrite(3,HIGH);
else digitalWrite(3,LOW);
Write the command line which scales analog value 0-1023 to percent range 0-100
val = map(val, 0, 1023, 0, 100);
for (int val = 0; val <=255; val +=5) {analogWrite (ledpin, val);
delay(2);
}
It increases the brightness of LED in every 2ms.
What does below program make?
if(tempC > 30)
{
digitalWrite(ledpin, HIGH);
delay(200); }
else
{
digitalWrite(ledpin, LOW);
delay(1000);
}
If temperature is higher than 30, lits the LED for every 200 ms, otherwise lits for every 1000ms.
A system consists of 5 LEDs and a potentiometer. Write the Arduino IDE sketch according to
application below.
void setup(){
for(int i= 1; i < 6 ; i++){
pinMode(led[i], OUTPUT);
}
Serial.begin(9600);
}
void loop(){
pot = 0;
pot = analogRead(analog);
if(pot>= 0 && pot <= 200 ){
digitalWrite(led[1],HIGH);
digitalWrite(led[2],LOW);
digitalWrite(led[3],LOW);
digitalWrite(led[4],LOW);
digitalWrite(led[5],LOW);
}
else if(pot <= 400 && pot >= 200){
digitalWrite(led[1],LOW);
digitalWrite(led[2],HIGH);
digitalWrite(led[3],LOW);
digitalWrite(led[4],LOW);
digitalWrite(led[5],LOW);
}
else if(pot <= 600 && pot >= 400){
digitalWrite(led[1],LOW);
digitalWrite(led[2],LOW);
digitalWrite(led[3],HIGH);
digitalWrite(led[4],LOW);
digitalWrite(led[5],LOW);
}
else if(pot<= 800 && pot >= 600){
digitalWrite(led[1],LOW);
digitalWrite(led[2],LOW);
digitalWrite(led[3],LOW);
digitalWrite(led[4],HIGH);
digitalWrite(led[5],LOW);
}
else if(pot <=1000 && pot >= 800){
digitalWrite(led[1],LOW);
digitalWrite(led[2],LOW);
digitalWrite(led[3],LOW);
digitalWrite(led[4],LOW);
digitalWrite(led[5],HIGH);
}
Serial.println(pot);
delay(100);
}
A system consists of two LEDs, one of is green and one of is red. Write the Arduino IDE sketch
which provides to unlit one of the LED and lit the other for each keystroke.
int buttonPin=2;
int greenLED=9;
int redLED=10;
boolean state;
void setup(){
pinMode(buttonPin, INPUT);
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
boolean state = HIGH;
}
void loop(){
if (digitalRead(buttonPin)==HIGH){
digitalWrite(greenLED, state);
digitalWrite(redLED, !state);
state = !state;
}
}
In order to configure 12m range digitalmeter which is potentiometer controlled write the Arduino
IDE sketch that lits 12 of LEDs one by one for every variation of distance.
int potPin = 0;
int i = 0;
void setup()
{
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
void loop()
{
for (i = 1; i<=12; i++);
digitalWrite(i, LOW);