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

COMP 1045 Lab 3_F24

The document outlines a lab assignment for COMP 1045 involving the use of a potentiometer and an RGB LED with an Arduino. It includes instructions for uploading source code to read values from a rotation sensor, controlling the RGB LED color sequence based on the sensor input, and allowing user-defined color patterns. The assignment progresses through levels of complexity, culminating in a program that handles multiple color inputs and error messages for invalid entries.

Uploaded by

fetat29455
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

COMP 1045 Lab 3_F24

The document outlines a lab assignment for COMP 1045 involving the use of a potentiometer and an RGB LED with an Arduino. It includes instructions for uploading source code to read values from a rotation sensor, controlling the RGB LED color sequence based on the sensor input, and allowing user-defined color patterns. The assignment progresses through levels of complexity, culminating in a program that handles multiple color inputs and error messages for invalid entries.

Uploaded by

fetat29455
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

COMP 1045 Lab 3

Circuit diagram: Connect a potentiometer and an RGB LED to the bread board

Level 1: Upload the source code and run it. Also open up the serial monitor on the bottom to
see what values you can read from the rotation sensor.

Source code:

int rotationPin = A0; //The rotation sensor is plugged into pin A0 of the Arduino.
int data=0; //Used to store data from sensor.

void setup() { //The Setup function runs once.


Serial.begin(9600); //This will enable the Arduino to send data to the Serial
//monitor.
pinMode(rotationPin,INPUT);
}

void loop() { //The loop function runs forever.


data = analogRead(rotationPin); //Read the value from the light sensor and store it
//in the lightData variable.
Serial.print("Rotation value =");
Serial.println(data); //Print the data to the serial port.
delay(1000); //Wait 1 second (1000mS) before running again.
}
Level2: Write a program that displays the following color sequence on the RGB LED (D9-D11)
Red, Green, Blue. The speed at which the color changes is controlled by Rotation dial A0 on the
board. As you turn the dial the speed of the RGB changes. When the dial is at zero the RGB
speed is the slowest, when the dial is at max the speed is at max.

Level 3: Use the rotation sensor to cycle through the colours of the rainbow. (ROYGBP)
depending on the value of the rotation sensor. (exL 0-150 = red from 150-300= Orange). Look
up the RGB value for each colour and use analogWrite() to get the proper colours.

Level 4:
Step #1: Create a code that asks the user to input a pattern of colours using R, G or B. Then
display that sequence of colours. Ex: "Please input any combination of R, G or B letters". You
can assume that they will not use other letters. Reference 1 Reference 2

Step #2 Add other colours to the choices available to the user; C = cyan, M = Magenta, Y =
Yellow, W = White. As well as lower case letters. If the user inputs an invalid letter a message
should be displayed to the serial monitor.

Full marks demo input → RgbdCMyWs

Output→ Show's all 7 colours properly and outputs "Invalid colour" twice.

You might also like