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.
Dependencies: Led SDFileSystem mbed
main.cpp
- Committer:
- MAlmazan
- Date:
- 2017-06-11
- Revision:
- 2:f3ceb5d7b70c
- Parent:
- 0:7373f4ac36fb
File content as of revision 2:f3ceb5d7b70c:
#include "mbed.h"
#include "SDFileSystem.h"
#include "LedSetup.h"
DigitalIn sw2(SW2);
DigitalIn sw3(SW3);
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
FILE *fp;
bool valorLED = false;
//Prende/Apaga el LED
int Boton2() {
if (sw2 == 0) {
if (valorLED) {
LEDEstado(false);
return 0;
} else {
LEDEstado(true);
return 1;
}
} else {
return -1;
}
}
//Setea el color del LED al azar
bool Boton3() {
if (sw3 == 0) {
ColorLEDRandom();
return true;
} else {
return false;
}
}
//No lo cierra porque se va a usar permanentemente
void CrearArchivo() {
mkdir("/sd", 0777);
fp = fopen("/sd/log.txt", "w");
}
int main() {
CrearArchivo();
while (true) {
if ((Boton2()) == 1){
fprintf(fp, "Se prendio el LED! (Boton 2)\n");
} else if ((Boton2()) == 0){
fprintf(fp, "Se apago el LED (Boton 2)\n");
}
//para evitar que el boton sense constantemente sus cambios
wait(0.2f);
if (Boton3()) {
fprintf(fp, "Se cambio el color aleatoriamente! (Boton 3)\n");
}
//para evitar que el boton sense constantemente sus cambios
wait(0.2f);
}
}