Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- aleksey136
- Date:
- 2021-10-20
- Revision:
- 2:e2441887b6d5
- Parent:
- 1:2b60776a9c3d
File content as of revision 2:e2441887b6d5:
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
#include "platform/mbed_thread.h"
// Blinking rate in milliseconds
//#define BLINKING_RATE_MS 5000
/*DigitalIn mybutton(USER_BUTTON);
DigitalOut myled(LED1);
int main()
{
mybutton.mode(PullUp);
while(1) {
printf("Button state is: %d\n\r", mybutton.read());
if (mybutton == 0) { // Button is pressed
myled = !myled; // Toggle the LED state
wait_ms(200); // 200 ms
}
}
}*/
/*PwmOut PWM1(LED1);
int main()
{
PWM1.period(0.500); // set PWM period to 10 ms
PWM1=0.5; // set duty cycle to 50%
}*/
/*Serial pc(USBTX, USBRX); // tx, rx
PwmOut led(LED1);
float brightness=0.0;
int main()
{
pc.printf("Control of LED dimmer by host terminal\n\r");
pc.printf("Press 'u' = brighter, 'd' = dimmer\n\r");
while(1) {
char c = pc.getc();
wait(0.001);
if((c == 'u') && (brightness < 0.1)) {
brightness += 0.001;
led = brightness;
}
if((c == 'd') && (brightness > 0.0)) {
brightness -= 0.001;
led = brightness;
}
pc.printf("%c %1.3f \n \r",c,brightness);
}
}*/
/*AnalogIn my_adc(PA_7); //D11 on board
DigitalOut led(LED1);
int main()
{
printf("\nSTM32 ADC example\n");
while(1) {
printf("ADC read = %f\n\r", (my_adc.read()*100));
led = !led;
wait_ms(1000);
}
}*/
/*DigitalIn mybutton(D7);
DigitalOut myled(LED1);
int main() {
mybutton.mode(PullNone);
while(1) {
printf("Button state is: %d\n\r", mybutton.read());
if (mybutton == 0) { // Button is pressed
myled = !myled; // Toggle the LED state
wait(0.2); // 200 ms
}
}
}*/
DigitalOut led(LED1);
DigitalIn mybutton1(A4);
DigitalIn mybutton2(A5);
DigitalIn mybutton3(D2);
DigitalIn mybutton4(D7);
DigitalOut rele(D3);
int main()
{
int a=0;
mybutton1.mode(PullNone);
mybutton2.mode(PullNone);
mybutton3.mode(PullNone);
mybutton4.mode(PullNone);
while(1) {
led = 1;
rele = 0;
if (mybutton1.read()==0){
if (a==0){
printf("Button1 state is: %d\n\r", mybutton1.read());
a=a+1;
wait(0.2);
}
}
if (mybutton2.read()==0){
if (a==1){
printf("Button2 state is: %d\n\r", mybutton2.read());
a++;
wait(0.2);
}
else{
a=0;
wait(0.2);
}
}
if (mybutton3.read()==0){
if (a==2){
printf("Button3 state is: %d\n\r", mybutton3.read());
a++;
wait(0.2);
}
else{
a=0;
wait(0.2);
}
}
if (mybutton4.read()==0){
if (a==3){
printf("Button4 state is: %d\n\r", mybutton4.read());
a++;
wait(0.2);
}
else{
a=0;
wait(0.2);
}
}
if (a==4) {
rele=!rele;
for (int i=0;i<10;i++){
led = !led;
wait(1);
}
rele=!rele;
a=0;
}
printf("The code is entered on: %d\n\r", a);
wait(0.2);
}
}