0% found this document useful (0 votes)
24 views4 pages

Electronics Task 2 River-Shofay

dff

Uploaded by

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

Electronics Task 2 River-Shofay

dff

Uploaded by

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

9/10 Digitech – Term 4 2023 Name: River

Electronics – Task 2
Task: Use buttons to activate each colour of a tricolour LED.

This is the circuit you will be writing code for:

Each button controls one colour of the LED. The colour turns on when the button is held down, and
turns off when the button is released. More than one button can be pressed at a time to combine
colours.

Note: It’s difficult to press more than one button at a time in Tinkercad.

(Scroll to next page for planning section)


Planning:

Make a flowchart for your algorithm. You may write/draw here or post a screenshot.

Button one = red


Button two = blue
Button three on = green

Code:

Access the circuit in Tinkercad and build your code using either blocks or text.

If you use blocks, post a screenshot of the blocks.

If you use text, copy and paste the text.

Extension: Make your code easier to follow by nicknaming the pins and using //comments.
paste your code or screenshot here:
void setup()
{
pinMode(6, INPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(5, INPUT);
pinMode(4, INPUT);
}

void loop()
{
if (digitalRead(6) == 1) {
digitalWrite(11, HIGH);

} else {
digitalWrite(11, LOW);

}
if (digitalRead(5) == 1) {
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
} else {
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
}
if (digitalRead(4) == 1) {
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
} else {
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
}
delay(10);
}

Test:

Did your code run as you expected it to? Explain:

Yes it did
Improve your code if you need to.

Paste your improved code or screenshot here when you’re done.


Add different settings for example flashing.

You might also like