Task 2,3,4 - Week2
Task 2,3,4 - Week2
1-
–2
TASK 3 – WEEK 2
–1
–2
TASK 4 – WEEK 2
:STEPS
:Decomposition -
Decomposition is one of the four cornerstones of
Computer Science. It involves breaking down a complex
problem or system into smaller parts that are more
manageable and easier to understand. The smaller parts can
then be examined and solved, or designed individually, as
.they are simpler to work with
- Pattern Recognition:
Pattern recognition in programming is the process of
recognizing patterns in input data. It involves finding
similarities or characteristics that some of the problems
share.
- Abstraction:
Abstraction is used to hide background details or any unnecessary
implementation about the data so that users only see the required
information. It is one of the most important and essential features of
object-oriented programming.
-Algorithmic Thinking:
Algorithmic thinking is a way of getting to a solution through the clear
definition of the steps needed nothing happens by magic. Rather than
coming up with a single answer to a problem, like 42, pupils develop
algorithms.
Ultrasonic
The HC-SR04 Ultrasonic Sensor operates on the principle
of ultrasonic wave propagation. It consists of two main
components: the ultrasonic transducer and the
microcontroller sensor. The ultrasonic transducer emits high-
frequency sound waves, which then bounce off objects in its
path.
- Example of code:
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
//
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
}
RGB LED
The RGB LED can emit any colors by mixing the 3 basic colors red, green
and blue. Actually, it consists of 3 separate LEDs red, green and blue
packed together in a single case.
TYPES:
• common anode
In a common anode RGB LED, the anode of the internal LEDs are all
connected to the external anode lead. To control each color, you need
to apply a LOW signal or ground to the red, green, and blue leads and
connect the anode lead to the positive terminal of the power supply
• common cathode
In a common cathode RGB LED, the cathode of the internal LEDs are all
connected to the external cathode lead. To control each color, you
need to apply a HIGH signal or VCC to the red, green, and blue leads
and connect the anode lead to the negative terminal of the power
supply
LOGIC OPERATORS:
-
- if statement:
if (expression1)
{ // Start of if statement block
// execute this if statement block only if expression1 is true
} // End of if statement block
// statements following the if statement block
- Else if statement:
-
For loop :
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
{)(void setup
pinMode(2, OUTPUT);
pinMode(3, OUTPUT); for(i=0; i<10; i++)
For
pinMode(4, OUTPUT); loop { pinMode(i,
pinMode(5, OUTPUT); }OUTPUT); }
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);}
EX1&&EX2
EX1 || EX2
Example for code :