0
0
Embedded Cprogramming~20 mins

Writing HIGH and LOW to output pins in Embedded C - Mini Project: Build & Apply

Choose your learning style9 modes available
Writing HIGH and LOW to Output Pins
📖 Scenario: You are working with a simple microcontroller board. You want to control two LEDs connected to output pins. One LED should be turned ON (HIGH) and the other LED should be turned OFF (LOW).
🎯 Goal: Write a program that sets two output pins: one to HIGH and the other to LOW, to control two LEDs.
📋 What You'll Learn
Create two variables representing output pins named pin1 and pin2 with values 5 and 6 respectively.
Create a variable called HIGH with value 1 and a variable called LOW with value 0.
Write code to set pin1 to HIGH and pin2 to LOW using a function called digitalWrite.
Print the states of pin1 and pin2 to the console.
💡 Why This Matters
🌍 Real World
Controlling LEDs or other devices by setting microcontroller pins HIGH or LOW is a basic task in embedded systems.
💼 Career
Embedded software engineers often write code to control hardware pins to turn devices on or off.
Progress0 / 4 steps
1
Define Output Pins
Create two integer variables called pin1 and pin2 and set them to 5 and 6 respectively.
Embedded C
Need a hint?

Use int to declare the pins and assign the numbers 5 and 6.

2
Define HIGH and LOW Values
Create two integer variables called HIGH and LOW and set them to 1 and 0 respectively.
Embedded C
Need a hint?

HIGH means ON (1), LOW means OFF (0).

3
Set Pins to HIGH and LOW
Use the function digitalWrite to set pin1 to HIGH and pin2 to LOW.
Embedded C
Need a hint?

Call digitalWrite twice, once for each pin and value.

4
Print Pin States
Print the states of pin1 and pin2 using printf in the format: "Pin 5 is HIGH" and "Pin 6 is LOW".
Embedded C
Need a hint?

Use printf with %d to insert pin numbers and print the states.