Ruleta
main.cpp@1:b11ca82c2be8, 2013-10-31 (annotated)
- Committer:
- darkmx4
- Date:
- Thu Oct 31 19:05:52 2013 +0000
- Revision:
- 1:b11ca82c2be8
- Parent:
- 0:a176fa6b4afd
TEC;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
darkmx4 | 0:a176fa6b4afd | 1 | // Analog Read |
darkmx4 | 0:a176fa6b4afd | 2 | #include "mbed.h" |
darkmx4 | 0:a176fa6b4afd | 3 | |
darkmx4 | 0:a176fa6b4afd | 4 | Serial pc(USBTX,USBRX);// tx, rx |
darkmx4 | 0:a176fa6b4afd | 5 | |
darkmx4 | 0:a176fa6b4afd | 6 | DigitalOut led1(PTD4); |
darkmx4 | 0:a176fa6b4afd | 7 | DigitalOut led2(PTA2); |
darkmx4 | 0:a176fa6b4afd | 8 | DigitalOut led3(PTA4); |
darkmx4 | 0:a176fa6b4afd | 9 | DigitalOut led4(PTA5); |
darkmx4 | 0:a176fa6b4afd | 10 | DigitalOut led5(PTC8); |
darkmx4 | 0:a176fa6b4afd | 11 | DigitalOut led6(PTC9); |
darkmx4 | 0:a176fa6b4afd | 12 | DigitalOut led7(PTA13); |
darkmx4 | 0:a176fa6b4afd | 13 | DigitalOut led8(PTD5); |
darkmx4 | 1:b11ca82c2be8 | 14 | BusOut leds(PTD4, PTA12, PTA4, PTA5, PTC8, PTC9, PTA13, PTD5); |
darkmx4 | 0:a176fa6b4afd | 15 | AnalogIn pot(PTB0); |
darkmx4 | 0:a176fa6b4afd | 16 | DigitalIn boton(PTB1); |
darkmx4 | 0:a176fa6b4afd | 17 | DigitalIn botonr(PTB2); |
darkmx4 | 0:a176fa6b4afd | 18 | |
darkmx4 | 0:a176fa6b4afd | 19 | int score = 100; |
darkmx4 | 0:a176fa6b4afd | 20 | int on; |
darkmx4 | 0:a176fa6b4afd | 21 | |
darkmx4 | 0:a176fa6b4afd | 22 | int main() { |
darkmx4 | 0:a176fa6b4afd | 23 | while(1){ |
darkmx4 | 0:a176fa6b4afd | 24 | |
darkmx4 | 0:a176fa6b4afd | 25 | on = 1; |
darkmx4 | 0:a176fa6b4afd | 26 | leds = on; |
darkmx4 | 0:a176fa6b4afd | 27 | wait(pot + .015); |
darkmx4 | 0:a176fa6b4afd | 28 | on = on <<1; |
darkmx4 | 0:a176fa6b4afd | 29 | |
darkmx4 | 0:a176fa6b4afd | 30 | if(on ==256) |
darkmx4 | 0:a176fa6b4afd | 31 | { |
darkmx4 | 0:a176fa6b4afd | 32 | on = 1; |
darkmx4 | 0:a176fa6b4afd | 33 | } |
darkmx4 | 0:a176fa6b4afd | 34 | |
darkmx4 | 0:a176fa6b4afd | 35 | boton.mode(PullUp); |
darkmx4 | 0:a176fa6b4afd | 36 | botonr.mode(PullUp); |
darkmx4 | 0:a176fa6b4afd | 37 | |
darkmx4 | 0:a176fa6b4afd | 38 | pc.printf("Tu puntaje es de 100 puntos.\n"); |
darkmx4 | 0:a176fa6b4afd | 39 | |
darkmx4 | 0:a176fa6b4afd | 40 | char c = pc.getc(); |
darkmx4 | 0:a176fa6b4afd | 41 | |
darkmx4 | 0:a176fa6b4afd | 42 | if(botonr ==0) |
darkmx4 | 0:a176fa6b4afd | 43 | { |
darkmx4 | 0:a176fa6b4afd | 44 | wait(0.5); |
darkmx4 | 0:a176fa6b4afd | 45 | score = 100; |
darkmx4 | 0:a176fa6b4afd | 46 | pc.printf("Reiniciando"); |
darkmx4 | 0:a176fa6b4afd | 47 | } |
darkmx4 | 0:a176fa6b4afd | 48 | else |
darkmx4 | 0:a176fa6b4afd | 49 | |
darkmx4 | 0:a176fa6b4afd | 50 | if(boton==0 || led8 ==1) |
darkmx4 | 0:a176fa6b4afd | 51 | { |
darkmx4 | 0:a176fa6b4afd | 52 | wait(0.5); |
darkmx4 | 0:a176fa6b4afd | 53 | score += 100; |
darkmx4 | 0:a176fa6b4afd | 54 | pc.printf("Felicidades! Ganaste 10 puntos.\n"); |
darkmx4 | 0:a176fa6b4afd | 55 | wait(0.5); |
darkmx4 | 0:a176fa6b4afd | 56 | } |
darkmx4 | 0:a176fa6b4afd | 57 | else |
darkmx4 | 0:a176fa6b4afd | 58 | |
darkmx4 | 0:a176fa6b4afd | 59 | if(boton==0 || led8 != 1) |
darkmx4 | 0:a176fa6b4afd | 60 | { |
darkmx4 | 0:a176fa6b4afd | 61 | wait(0.5); |
darkmx4 | 0:a176fa6b4afd | 62 | score -= 250; |
darkmx4 | 0:a176fa6b4afd | 63 | pc.printf("Fallaste, Pierdes 25 puntos.\n"); |
darkmx4 | 0:a176fa6b4afd | 64 | wait(0.5); |
darkmx4 | 0:a176fa6b4afd | 65 | } |
darkmx4 | 0:a176fa6b4afd | 66 | } |
darkmx4 | 0:a176fa6b4afd | 67 | } |