[go: up one dir, main page]

0% found this document useful (0 votes)
9 views2 pages

Embedded C Practice Manual

The document contains a manual for Embedded C practice programs with various examples. It includes code snippets for tasks such as blinking an LED, controlling an LED with a button, adjusting LED brightness with PWM, toggling an LED using interrupts, reading an analog sensor, and sending messages via UART communication. Each example outlines the objective and provides corresponding code for implementation.

Uploaded by

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

Embedded C Practice Manual

The document contains a manual for Embedded C practice programs with various examples. It includes code snippets for tasks such as blinking an LED, controlling an LED with a button, adjusting LED brightness with PWM, toggling an LED using interrupts, reading an analog sensor, and sending messages via UART communication. Each example outlines the objective and provides corresponding code for implementation.

Uploaded by

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

Embedded C Practice Programs Manual

Blink LED

- Objective: Turn an LED on and off every 1 second


- Code Snippet (Arduino C):
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}

Button Controlled LED

- Objective: Turn LED on when button is pressed


- Code Snippet:
void setup() {
pinMode(2, INPUT);
pinMode(13, OUTPUT);
}
void loop() {
int state = digitalRead(2);
digitalWrite(13, state);
}

PWM LED Brightness Control

- Objective: Fade an LED using PWM


- Code Snippet:
void setup() {
pinMode(9, OUTPUT);
}
void loop() {
for(int i = 0; i < 255; i++) {
analogWrite(9, i);
delay(10);
}
for(int i = 255; i > 0; i--) {
analogWrite(9, i);
delay(10);
}
}

Interrupt-Based LED Toggle

- Objective: Toggle LED on interrupt from a button


- Code Snippet:
Embedded C Practice Programs Manual

volatile int state = LOW;


void setup() {
pinMode(2, INPUT);
pinMode(13, OUTPUT);
attachInterrupt(digitalPinToInterrupt(2), toggle, RISING);
}
void loop() {
digitalWrite(13, state);
}
void toggle() {
state = !state;
}

Analog Sensor Reading

- Objective: Read value from a potentiometer and print to Serial


- Code Snippet:
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(A0);
Serial.println(value);
delay(500);
}

UART Communication

- Objective: Send a message to serial monitor repeatedly


- Code Snippet:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hello from Embedded C!");
delay(1000);
}

You might also like