0% found this document useful (0 votes)
2 views

Programming assignment

Uploaded by

Devrush Redlife
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programming assignment

Uploaded by

Devrush Redlife
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Activity: Arduino Programming Assessment

Submitted by: Sanjae Whyte

1. Part 1: Predict the result of an Arduino program.

• The given Arduino code will print numbers from 1 to 10 on the serial monitor,
each on a separate line.

2. Part 2: Predict the result of an Arduino program.

• This code will control a motor connected to pins 11 and 10 of the Arduino
based on the distance measured by the HC-SR04 sensor. If the distance is
greater than 10 inches, the motor will rotate in one direction (assumed
forward). If the distance is less than 2 inches, the motor will rotate in the
opposite direction. Otherwise, the motor will stop.

3. Part 3: Arduino program from a given flowchart.


int greenLedPin = 7; // Pin for green LED
int redLedPin = 8; // Pin for red LED
int buttonPin = 9; // Pin for button input

void setup() {
// Set pin modes
pinMode(greenLedPin, OUTPUT); // Green LED pin as output
pinMode(redLedPin, OUTPUT); // Red LED pin as output
pinMode(buttonPin, INPUT); // Button pin as input
// Begin serial communication
Serial.begin(9600);
}

void loop() {
// Read voltage at pin 9
int buttonState = digitalRead(buttonPin);

// Check if button is pressed


if (buttonState == HIGH) {
// Button is pressed
Serial.println("Button is pressed");
// Turn on green LED and turn off red LED
digitalWrite(greenLedPin, HIGH);
digitalWrite(redLedPin, LOW);
} else {
// Button is not pressed
// Turn on red LED and turn off green LED
digitalWrite(redLedPin, HIGH);
digitalWrite(greenLedPin, LOW);
}

// Delay to avoid reading the button state too quickly


delay(100);
}

4. Part 4: Flowchart for a given algorithm.

You might also like