21BLC1151LAB4
21BLC1151LAB4
21BLC1151LAB4
Submitted By
21BLC1151 –Aditya Kumar Jha
DATE: 29/01/2024
Date: 29-01-24
Hardware Required: Micro USB cable, NUCLEO64-STM32L152 Board, LEDs, Jumper Wires (M-F and M-
M), Breadboard, Buzzer
Procedure:
1. Go to ARM Keil Studio (https://studio.keil.arm.com) and log in
2. Select File → New → Mbed Project
3. Click the Example project drop-down list and select “mbed2-example-blinky”
4. In Project name field, provide the name of the new project and click Add project
5. Double click on the “main.cpp” file from the newly created project folder
6. Open Tera-term app and connect to Port.
7. Modify the code in the editor window as per the logic of your application
8. Check for any errors in the program under the “Problems” tab of the panels window
9. If no errors, connect the Nucleo Board to the computer using Micro USB Cable
10. Click Play icon (Run project) to upload and start the code execution on the board.
PROGRAM:
Lab Task-1: Controlling o board LED using USB Serial port
#include "mbed.h"
Serial pc(USBTX,USBRX);
DigitalOut myled(LED1);
int main(){
printf("Press a character:");
while(1)
Output:
#include "mbed.h"
Serial pc(USBTX,USBRX);
PwmOut led(PC_8);
float brightness=0.0;
int main() {
while(1) {
pc.printf("Enter the command to increase or decrease the brightness(I/D) :\r\n");
char c=pc.getc();
if((c=='i')){
pc.printf("Increasing the brightness by 10% : \r\n");
brightness+=0.1;
led=brightness;
}
if((c=='d')&&(brightness>0.0)){
pc.printf("Decreasing the brightness by 10% : \r\n");
brightness-=0.1;
led=brightness;
}
}
}
Output:
Serial pc(USBTX,USBRX);
AnalogIn ain(PC_3);
PwmOut PWM1(PC_8);
int main()
{
while(1)
{
float value = ain*5;
pc.printf("The reading of pot:%f",value);
wait(1);
PWM1.period(0.01);
PWM1 = ain;
}
}
#include "mbed.h"
Serial pc(USBTX,USBRX);
AnalogIn ain(PC_3);
DigitalOut LED1(PC_8);
DigitalOut LED2(PB_13);
DigitalOut LED3(PB_14);
DigitalOut LED4(PB_15);
DigitalOut LED5(PB_1);
int main()
{
while(1)
{ float value = ain*5;
if(value>=0 && value<1){
pc.printf("The reading of 0 to 1");
LED1 = 1;
LED2 = 0;
LED3 = 0;
LED4 = 0;
LED5 = 0;
wait(1);
}
if(value>=1 && value<2){
pc.printf("The reading of 1 to 2");
LED1 = 1;
LED2 = 1;
LED3 = 0;
LED4 = 0;
LED5 = 0;
wait(1);
}
if(value>=2 && value<3){
pc.printf("The reading of 2 to 3");
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 0;
LED5 = 0;
wait(1);
}
if(value>=3 && value<4){
pc.printf("The reading of 3 to 4");
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 1;
LED5 = 0;
wait(1);
}
if(value>=4 && value<5){}
pc.printf("The reading of 4 to 5");
LED1 = 1;
RESULT:
The LED glowing using user Input via tera term and also giving Instructions to LED via
potentiometer experiment is performed successfully.