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: mbed
Diff: main.cpp
- Revision:
- 1:87e57a5439b8
- Parent:
- 0:9f7581d1af6f
--- a/main.cpp Wed Jun 26 18:54:11 2019 +0000
+++ b/main.cpp Wed Sep 11 19:56:40 2019 +0000
@@ -1,6 +1,6 @@
/* ###########################################################################
** Archivo : main.c
-** Proyecto : STM32-F103C8_Plantilla
+** Proyecto : STM32-F103C8_Adivina
** Procesador : STM32F103C8
** Herramienta : Mbed
** Version : Driver 01.01
@@ -37,8 +37,8 @@
//#include "SysClockConf.h"
//#include "AnalogIn.h"
//#include "Led_RGB.h"
-//#include "Serial.h"
-//#include "stdio.h"
+#include "Serial.h"
+#include "stdio.h"
/*
:...............................................................................
@@ -49,26 +49,28 @@
#define off 1 // Estado para boton sin presionar
#define hold 2 // Estado para boton mantenido
#define release 3 // Estado para boton liberado
-#define Ticker_Rate 1000 // Periodo de interrupción (us)
+#define FALSE 0
+#define TRUE 1
+//#define Ticker_Rate 1000 // Periodo de interrupción (us)
/*
+-------------------------------------------------------------------------------
| Configuración de Puertos
+-------------------------------------------------------------------------------
*/
//confSysClock(); // Configure system clock (72MHz HSE clock, 48MHz USB clock)
-Ticker TimerInt; // Inicializa la Interrupción por Timer
-DigitalOut led_monitor(LED1); // Inicializa el LED Monitor
-DigitalOut led_testigo(PA_1); // Inicializa el LED Testigo
+//Ticker TimerInt; // Inicializa la Interrupción por Timer
+DigitalOut verde (LED1); // Inicializa el LED Monitor
+DigitalOut rojo (PB_1); // Inicializa el LED Testigo
Serial terminal(PA_2, PA_3); // Inicializa la Comunicación Serial a la PC
-PwmOut servo(PA_7); // Inicializa el PWM
-AnalogIn sensor1 (PB_0); // Inicializa Canal Analógico para sensor 1
+//PwmOut servo(PA_7); // Inicializa el PWM
+//AnalogIn sensor1 (PB_0); // Inicializa Canal Analógico para sensor 1
/*
+-------------------------------------------------------------------------------
| Variables Globales de Usuario
+-------------------------------------------------------------------------------
*/
-uint16_t Rate=Ticker_Rate/2; // Velocidad de barrido (500us = 0.5ms)
-uint16_t counter=250; // Cuenta inicial de 250us
+//uint16_t Rate=Ticker_Rate/2; // Velocidad de barrido (500us = 0.5ms)
+//uint16_t counter=250; // Cuenta inicial de 250us
/* END variables */
/*
@@ -78,8 +80,9 @@
*/
// Las Definiciones de Funciones Prototipo
// y Apuntadores a Vectores de Interrupciones van aquí !
-void TimerInt_OnInterrupt(void);
-void Blinking_Led(void);
+void Setup(void);
+//void TimerInt_OnInterrupt(void);
+//void Blinking_Led(void);
/* END prototypes */
/* END definitions */
@@ -92,17 +95,67 @@
*/
int main()
{ // Inicialización de variables, puertos e interrupciones
-confSysClock(); // Inicialización del Sistema, Configure system clock (72MHz HSE clock, 48MHz USB clock)
-TimerInt.attach_us(&TimerInt_OnInterrupt, Ticker_Rate); // Le asigna el periodo de interrupción de 1ms (Ticker_Rate=1000)
+void confSysClock(); // Inicialización del Sistema, Configure system clock (72MHz HSE clock, 48MHz USB clock)
+void Setup(void);
+//TimerInt.attach_us(&TimerInt_OnInterrupt, Ticker_Rate); // Le asigna el periodo de interrupción de 1ms (Ticker_Rate=1000)
-terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial.
-terminal.printf(" System is Wake Up!.\n\r");
+//terminal.baud(115200); // Se configura la velocidad de transmisión e inicia la comunicación serial.
+terminal.printf(" ADIVINA \n\r");
+rojo = off;
+verde = off;
while (true) // El Lazo del Programa principal está aquí !!!
{
- Blinking_Led(); // Parapadeo del LED por Software
- servo = sensor1.read(); //
- terminal.printf("Blink \r\n");
+ Inicio: terminal.printf("DIGITE UN NUMERO SECRETO DE 0 A 9 \r\n");
+ char secreto = terminal.getc();
+ rojo = on;
+ verde = on;
+ Intenta: terminal.printf("ADIVINA EL NUMERO \r\n");
+ char respuesta = terminal.getc();
+ if( secreto < respuesta )
+ {
+ terminal.printf("Es mas BAJO \r\n");
+ rojo = on;
+ verde = off;
+ goto Intenta;
+ }
+ if(secreto > respuesta )
+ {
+ terminal.printf("Es mas ALTO \r\n");
+ rojo = off;
+ verde = on;
+ goto Intenta;
+ }
+ if( secreto == respuesta )
+ {
+ terminal.printf("CORRECTO!, Es igual a: %c \r\n", secreto);
+ rojo = off;
+ verde = on;
+ wait(1.0);
+ rojo = off;
+ verde = off;
+ wait(1.0);
+ rojo = off;
+ verde = on;
+ wait(1.0);
+ terminal.printf("ERES UN GENIO !!! \r\n");
+ wait(1.0);
+ rojo = on;
+ verde = off;
+ wait(1.0);
+ rojo =off;
+ verde = on;
+ }
+ terminal.printf("Quieres intentarlo de nuevo? \r\n");
+ terminal.printf("0 = NO \r\n 1 = SI \r\n");
+ char opcion = terminal .getc();
+ if(opcion =='1') goto Inicio;
+ else if(opcion == '0')
+ {
+ terminal.printf("GAME OVER \r\n");
+ break;
+ }
+
}
}
/* END main */
@@ -113,7 +166,7 @@
................................................................................
*/
// Las Rutinas de Atención a Interrupciones van aquí !
-void TimerInt_OnInterrupt() // Rutina de Atención al Ticker
+/*void TimerInt_OnInterrupt() // Rutina de Atención al Ticker
{
counter--; // Aquí va la Rutina de Servicio !
if (!counter)
@@ -122,7 +175,7 @@
led_monitor = !led_monitor; // Parapadeo del LED por Interrupción (LED Toggled)
counter = Rate; // Restablece el contador, Le asigna el periodo de 0.5ms (Rate=500)
}
-}
+}*/
/* END Events */
/*
________________________________________________________________________________
@@ -131,14 +184,16 @@
|_______________________________________________________________________________
*/
// Las Funciones Prototipo van aquí !
-void Blinking_Led() // Software Blinking routine for LED
+void Setup() // Software Blinking routine for LED
{
// The on-board LED is connected, via a resistor, to +3.3V (not to GND).
// So to turn the LED on or off we have to set it to 0 or 1 respectively
- led_testigo = 1; // turn the LED on (using Positive Logic)
- wait_ms(200); // 200 millisecond
- led_testigo = 0; // turn the LED off (using Positive Logic)
- wait_ms(1000); // 1000 millisecond
+ terminal.baud(9600);
+ terminal.printf("System is Wake Up!.\n\r");
+ //led_testigo = 1; // turn the LED on (using Positive Logic)
+ //wait_ms(200); // 200 millisecond
+ //led_testigo = 0; // turn the LED off (using Positive Logic)
+ //wait_ms(1000); // 1000 millisecond
}
/* END functions */