Beruflich Dokumente
Kultur Dokumente
delay(250);
digitalWrite(6, LOW);
delay(250);
digitalWrite(6,HIGH);
delay(250);
digitalWrite(6, LOW);
delay(250);
digitalWrite(13, LOW);
delay(250);
digitalWrite(6, LOW);
delay(250);
digitalWrite(6,HIGH);
delay(250);
digitalWrite(6, LOW);
delay(250);
Observed behavior:
Two LEDs operate at a different sequence at the same time. LED on the pin 13 when
turn on the LED on pin 6 complete 4 on and off cycle. Again when LED on the pin 13
when turn off the LED on pin 6 complete 4 on and off cycle.
void loop()
{
buttonState = digitalRead(buttonPin);
pushbutton value
{
digitalWrite(ledPin, ledState);
toggle the LED
if (ledState == LOW)
what it was for next toggle
{
ledState = HIGH;
}
else
{
ledState = LOW;
}
}
previousButtonState = buttonState;
next comparison
}
Observed behavior:
Due to polling the program wont response if the button pressed too quickly. The
program may not executing the digitalRead() function too quickly resulting no
response from the Arduino. To avoid this add a 0.5 sec delay in our program in our
task-4.
/*
Program name: Analog input(potentiometer,digital(LED) output
Md Assad-Uz-Zaman, MECHENG-479, Sep. 26, 2016
Prints the value of the potentiometer in decimal and binary. Program
loops endlessly at 2.5 Hz. Also
the output is displaing its binary value through the 7 lED HIGH and LOW
status.For 7 LED there is larger
load on the circuit so the LEDs are connected to the Arduino board
through an amplifier chip.
Arduino resource used:
Arduino analog pin 0, analog input,Potentiometer
PWM pin 7,8,9,10,11,12,13; digital output, ULN2003 driver chip
*/
// Constants and variables section
const int PotPin = 15; // input pin for the potentiometer
int PotReading = 0;
// variable to hold potentiometer value
void setup()
{
Serial.begin(9600); // Opens the default serial channel at 9600 baud
pinMode(13,OUTPUT); // initialize pin as an output for ULN2003 pin 1B as
input(Most significant Bit)
pinMode(12,OUTPUT); // initialize pin as an output for ULN2003 pin 2B as input
pinMode(11,OUTPUT); // initialize pin as an output for ULN2003 pin 3B as input
pinMode(10,OUTPUT); // initialize pin as an output for ULN2003 pin 4B as input
pinMode(9,OUTPUT); // initialize pin as an output for ULN2003 pin 5B as input
pinMode(8,OUTPUT); // initialize pin as an output for ULN2003 pin 6B as input
pinMode(7,OUTPUT); // initialize pin as an output for ULN2003 pin 7B as
input(Lease significant Bit)
}
void loop()
{
PotReading = analogRead(PotPin); // Read the pot
int x = PotReading/8;
Observed behavior:
By this program analog data from potentiometer is displayed in binary format
through 7 LEDs as a 7 bit data. If the decimal reading of potentiometer is 5 then the
sequence of the LED high and low status is 0000101.