Professional Documents
Culture Documents
void setup() {
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(1000); // Wait for one second
digitalWrite(ledPin, LOW); // Turn the LED off
delay(1000); // Wait for one second
}
b). Distinguish between Von Neumann Architecture and the Harvard Architecture as used
in Classification of Microcontroller. [4marks]
c). We can get LEDs in a variety of colors these days, but what about an LED that can
change color. We all know that we can use a combination of Red, Green, and Blue (RGB)
to get any color. In this question, you are to design and write code for an Arduino
application that can give 16 million color combinations with an RGB LED.
i) Draw a possible wire connection on the breadboard for the case [4 marks]
RGB LED
|||
|||
|||
|||
|||
|||
|||
|||
+---| | |---+
| |
| Arduino Uno |
| |
+------------+
ii) Write code that will make the RGB LED change the few colors. [6 marks]
// Define the pins for the RGB LED
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
void setup() {
// Set the RGB pins as outputs
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// Cycle through some example colors
setColor(255, 0, 0); // Red
delay(1000);
setColor(0, 255, 0); // Green
delay(1000);
setColor(0, 0, 255); // Blue
delay(1000);
setColor(255, 255, 0); // Yellow
delay(1000);
setColor(255, 0, 255); // Magenta
delay(1000);
setColor(0, 255, 255); // Cyan
delay(1000);
setColor(255, 255, 255); // White
delay(1000);
}
i) 0 s [3 marks] - 0
ii) 1 s [3 marks] -1
iii) 2 s [3 marks] - 0
iv) 3 s [3 marks]-1
v) 4 s [3 marks] -1
void setup() {
// Initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// Initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// Read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
One common example of an embedded system is a digital watch2. A digital watch is designed
to perform a specific task, which is to keep and display time. It operates independently without
any need for user interaction, except for setting the time. The watch uses a microcontroller to
keep track of time and to control the display. Despite its complex functionality, a digital watch is
compact, affordable, and requires very little power to operate
void setup() {
mySerial.begin(9600);
}
void loop() {
counterValue++; // Increment counter value
mySerial.write(START_BYTE);
mySerial.write(counterValue);
mySerial.write(staticValue);
mySerial.write(checksum);