interesting

Dependencies:   C12832_lcd mbed

Fork of Bootcamp-Interrupt_Polling_Joystick by avnish aggarwal

Committer:
joeroop
Date:
Wed Apr 16 04:31:33 2014 +0000
Revision:
4:9b1a6ddf5fee
Parent:
3:27ec45bc9078
interesting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
avnisha 1:102ef7d39407 1
avnisha 1:102ef7d39407 2 #include "mbed.h"
avnisha 1:102ef7d39407 3
avnisha 2:d18857b99d3c 4 //
avnisha 2:d18857b99d3c 5 // ignore interrupt version till we discuss that topic
avnisha 2:d18857b99d3c 6 //
avnisha 2:d18857b99d3c 7
avnisha 2:d18857b99d3c 8 #ifdef INTERRUPT
avnisha 1:102ef7d39407 9 InterruptIn fire(p14);
avnisha 1:102ef7d39407 10 DigitalOut led(LED1);
avnisha 1:102ef7d39407 11 DigitalOut flash(LED4);
avnisha 1:102ef7d39407 12
avnisha 1:102ef7d39407 13 void ISR1() {
avnisha 1:102ef7d39407 14 led = !led;
avnisha 1:102ef7d39407 15 }
avnisha 1:102ef7d39407 16
avnisha 1:102ef7d39407 17 int main()
avnisha 1:102ef7d39407 18 {
avnisha 1:102ef7d39407 19 fire.rise(&ISR1);
avnisha 1:102ef7d39407 20 fire.fall(&ISR1);
avnisha 1:102ef7d39407 21
avnisha 1:102ef7d39407 22 while (1) {
avnisha 1:102ef7d39407 23 flash = !flash;
avnisha 1:102ef7d39407 24 wait(0.25);
avnisha 1:102ef7d39407 25 }
avnisha 1:102ef7d39407 26 }
avnisha 1:102ef7d39407 27
avnisha 2:d18857b99d3c 28 #endif
avnisha 2:d18857b99d3c 29
chris 0:0e4db18afd77 30 #include "mbed.h"
joeroop 4:9b1a6ddf5fee 31 #include "C12832_lcd.h" //LCD interface
chris 0:0e4db18afd77 32
chris 0:0e4db18afd77 33 BusIn joy(p15,p12,p13,p16);
avnisha 3:27ec45bc9078 34 DigitalIn fire(p14);
chris 0:0e4db18afd77 35
joeroop 4:9b1a6ddf5fee 36
chris 0:0e4db18afd77 37 BusOut leds(LED1,LED2,LED3,LED4);
joeroop 4:9b1a6ddf5fee 38 C12832_LCD lcd;
joeroop 4:9b1a6ddf5fee 39
joeroop 4:9b1a6ddf5fee 40 int btns[] = {0, 0, 0, 0};
joeroop 4:9b1a6ddf5fee 41 char* btns_names[]= {"TOP", "BOT", "LFT", "RGT"};
chris 0:0e4db18afd77 42
chris 0:0e4db18afd77 43 int main()
chris 0:0e4db18afd77 44 {
joeroop 4:9b1a6ddf5fee 45 int t;
joeroop 4:9b1a6ddf5fee 46 lcd.locate(0,0);
chris 0:0e4db18afd77 47 while(1) {
chris 0:0e4db18afd77 48 if (fire) {
chris 0:0e4db18afd77 49 leds=0xf;
chris 0:0e4db18afd77 50 } else {
chris 0:0e4db18afd77 51 leds=joy;
joeroop 4:9b1a6ddf5fee 52 t = joy;
joeroop 4:9b1a6ddf5fee 53 //add the switch settings
joeroop 4:9b1a6ddf5fee 54 /*
joeroop 4:9b1a6ddf5fee 55 btns[0] += (t&0x1 > 0) ? 1 : 0;
joeroop 4:9b1a6ddf5fee 56 btns[1] += (t&0x2 > 0) ? 1 : 0;
joeroop 4:9b1a6ddf5fee 57 btns[2] += (t&0x4 > 0) ? 1 : 0;
joeroop 4:9b1a6ddf5fee 58 btns[3] += (t&0x8 > 0) ? 1 : 0;
joeroop 4:9b1a6ddf5fee 59 */
joeroop 4:9b1a6ddf5fee 60 if(t&0x1 > 0) btns[0]+=1;
joeroop 4:9b1a6ddf5fee 61 if(t&0x2 > 0) btns[1]+=1;
joeroop 4:9b1a6ddf5fee 62 if(t&0x4 > 0) btns[2]+=1;
joeroop 4:9b1a6ddf5fee 63 if(t&0x8 > 0) btns[3]+=1;
joeroop 4:9b1a6ddf5fee 64 lcd.locate(0,0); //{"TOP", "BOT", "LFT", "RGT"};
joeroop 4:9b1a6ddf5fee 65 lcd.printf("%s: %2d %2d ", btns_names[0],t&0x1, btns[0]);
joeroop 4:9b1a6ddf5fee 66 lcd.locate(70,0);
joeroop 4:9b1a6ddf5fee 67 lcd.printf("%s: %2d %2d ", btns_names[1],t&0x2, btns[1]);
joeroop 4:9b1a6ddf5fee 68 lcd.locate(0,10);
joeroop 4:9b1a6ddf5fee 69 lcd.printf("%s: %2d %2d ", btns_names[2],t&0x4, btns[2]);
joeroop 4:9b1a6ddf5fee 70 lcd.locate(70,10);
joeroop 4:9b1a6ddf5fee 71 lcd.printf("%s: %2d %2d ", btns_names[3],t&0x8, btns[3]);
joeroop 4:9b1a6ddf5fee 72
chris 0:0e4db18afd77 73 }
chris 0:0e4db18afd77 74 wait(0.1);
chris 0:0e4db18afd77 75 }
chris 0:0e4db18afd77 76 }
avnisha 2:d18857b99d3c 77