set led to common anode

Dependencies:   C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed

Fork of xively-dreamforce by Ilya Dmitrichenko

Committer:
frontispiece
Date:
Thu Nov 14 17:27:17 2013 +0000
Revision:
20:4bb2758223fb
Parent:
19:ca595d80895b
fixed LED common anode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xively 0:efdea27c3b81 1 #include "mbed.h"
xively 0:efdea27c3b81 2 #include "EthernetInterface.h"
xively 7:0eff5db44b8b 3
frontispiece 20:4bb2758223fb 4 #define XI_FEED_ID 60544303 // set Xively Feed ID (numerical, no quoutes)
frontispiece 20:4bb2758223fb 5 #define XI_API_KEY "l3JC4iQeiw7k5LGvoKAGydQnJ0ekmIDr7z8mh6fBh5j130hP" // set Xively API key (double-quoted string)
errordeveloper 10:86ffba646df1 6
errordeveloper 10:86ffba646df1 7 #include "app_board_io.h"
xively 7:0eff5db44b8b 8
xively 0:efdea27c3b81 9 #include "xively.h"
xively 0:efdea27c3b81 10 #include "xi_err.h"
xively 0:efdea27c3b81 11
errordeveloper 10:86ffba646df1 12 #include "MMA7660.h"
errordeveloper 10:86ffba646df1 13 #include "LM75B.h"
errordeveloper 11:bdf601a405fc 14 #include "C12832_lcd.h"
errordeveloper 10:86ffba646df1 15
xively 3:7ad3f6543b6e 16 LM75B tmp(p28, p27);
errordeveloper 15:7443df31ff5b 17 DigitalOut fan(p22);
errordeveloper 17:6457dc373c2d 18 PwmOut progress_led(LED1);
errordeveloper 11:bdf601a405fc 19 C12832_LCD lcd;
errordeveloper 11:bdf601a405fc 20
frontispiece 20:4bb2758223fb 21 DigitalOut r (p23);
frontispiece 20:4bb2758223fb 22 DigitalOut g (p24);
frontispiece 20:4bb2758223fb 23 DigitalOut b (p25);
errordeveloper 19:ca595d80895b 24
errordeveloper 11:bdf601a405fc 25 #include "logo.h"
xively 0:efdea27c3b81 26
frontispiece 20:4bb2758223fb 27 int main()
frontispiece 20:4bb2758223fb 28 {
errordeveloper 11:bdf601a405fc 29 lcd_print_xively_logo();
errordeveloper 16:878226cefdb1 30
xively 0:efdea27c3b81 31 EthernetInterface eth;
frontispiece 20:4bb2758223fb 32
xively 0:efdea27c3b81 33 int s = eth.init(); //Use DHCP
frontispiece 20:4bb2758223fb 34
frontispiece 20:4bb2758223fb 35 if( s != NULL ) {
frontispiece 20:4bb2758223fb 36 lcd_printf( "Could not initialise. Will halt!\n" );
xively 0:efdea27c3b81 37 exit( 0 );
frontispiece 20:4bb2758223fb 38 }
frontispiece 20:4bb2758223fb 39
xively 0:efdea27c3b81 40 s = eth.connect();
frontispiece 20:4bb2758223fb 41
frontispiece 20:4bb2758223fb 42 if( s != NULL ) {
xively 7:0eff5db44b8b 43 lcd_printf( "Could not connect. Will halt!\n" );
xively 0:efdea27c3b81 44 exit( 0 );
frontispiece 20:4bb2758223fb 45 } else {
frontispiece 20:4bb2758223fb 46 lcd_printf( "IP: %s\n", eth.getIPAddress() );
xively 0:efdea27c3b81 47 }
frontispiece 20:4bb2758223fb 48
errordeveloper 14:1bb008e28de8 49 xi_feed_t output_channels;
errordeveloper 14:1bb008e28de8 50 memset( &output_channels, NULL, sizeof( xi_feed_t ) );
frontispiece 20:4bb2758223fb 51
errordeveloper 14:1bb008e28de8 52 output_channels.feed_id = XI_FEED_ID;
errordeveloper 14:1bb008e28de8 53 output_channels.datastream_count = 1;
frontispiece 20:4bb2758223fb 54
errordeveloper 14:1bb008e28de8 55 output_channels.datastreams[0].datapoint_count = 1;
errordeveloper 14:1bb008e28de8 56 xi_datastream_t* temperature_datastream = &output_channels.datastreams[0];
errordeveloper 14:1bb008e28de8 57 strcpy( temperature_datastream->datastream_id, "temp" );
errordeveloper 14:1bb008e28de8 58 xi_datapoint_t* temp = &temperature_datastream->datapoints[0];
frontispiece 20:4bb2758223fb 59
errordeveloper 14:1bb008e28de8 60 xi_feed_t input_channels;
errordeveloper 14:1bb008e28de8 61 memset( &input_channels, NULL, sizeof( xi_feed_t ) );
xively 0:efdea27c3b81 62
errordeveloper 14:1bb008e28de8 63 input_channels.feed_id = XI_FEED_ID;
errordeveloper 14:1bb008e28de8 64 input_channels.datastream_count = 2;
frontispiece 20:4bb2758223fb 65
errordeveloper 14:1bb008e28de8 66 input_channels.datastreams[0].datapoint_count = 1;
errordeveloper 14:1bb008e28de8 67 xi_datastream_t* fan_ctl_datastream = &input_channels.datastreams[0];
errordeveloper 14:1bb008e28de8 68 strcpy( fan_ctl_datastream->datastream_id, "fan" );
errordeveloper 14:1bb008e28de8 69 xi_datapoint_t* fan_ctl = &fan_ctl_datastream->datapoints[0];
errordeveloper 14:1bb008e28de8 70
errordeveloper 14:1bb008e28de8 71 input_channels.datastreams[1].datapoint_count = 1;
errordeveloper 14:1bb008e28de8 72 xi_datastream_t* led_ctl_datastream = &input_channels.datastreams[1];
errordeveloper 14:1bb008e28de8 73 strcpy( led_ctl_datastream->datastream_id, "led" );
errordeveloper 14:1bb008e28de8 74 xi_datapoint_t* led_ctl = &led_ctl_datastream->datapoints[0];
frontispiece 20:4bb2758223fb 75
frontispiece 20:4bb2758223fb 76 // create the xively library context
xively 0:efdea27c3b81 77 xi_context_t* xi_context
frontispiece 20:4bb2758223fb 78 = xi_create_context( XI_HTTP, XI_API_KEY, output_channels.feed_id );
xively 0:efdea27c3b81 79
xively 0:efdea27c3b81 80 // check if everything works
frontispiece 20:4bb2758223fb 81 if( xi_context == NULL ) {
xively 0:efdea27c3b81 82 return -1;
xively 0:efdea27c3b81 83 }
xively 0:efdea27c3b81 84
errordeveloper 15:7443df31ff5b 85 while( true ) {
frontispiece 20:4bb2758223fb 86
frontispiece 20:4bb2758223fb 87 xi_set_value_f32( temp, tmp.read() );
frontispiece 20:4bb2758223fb 88
frontispiece 20:4bb2758223fb 89 printf( "Updating output channels...\r\n" );
frontispiece 20:4bb2758223fb 90 progress_led = 0.6;
frontispiece 20:4bb2758223fb 91 lcd_printf( "updating...\n" );
frontispiece 20:4bb2758223fb 92 xi_feed_update( xi_context, &output_channels );
frontispiece 20:4bb2758223fb 93 progress_led = 0.1;
frontispiece 20:4bb2758223fb 94 printf( " [ec:%s]\r\n", xi_get_last_error() );
frontispiece 20:4bb2758223fb 95
frontispiece 20:4bb2758223fb 96 printf( "Reading input channels...\r\n" );
frontispiece 20:4bb2758223fb 97 progress_led = 0.8;
frontispiece 20:4bb2758223fb 98 lcd_printf( "reading...\n" );
frontispiece 20:4bb2758223fb 99 xi_feed_get( xi_context, &input_channels );
frontispiece 20:4bb2758223fb 100 progress_led = 0.1;
frontispiece 20:4bb2758223fb 101 printf( " [ec:%s]\r\n", xi_get_last_error() );
frontispiece 20:4bb2758223fb 102
frontispiece 20:4bb2758223fb 103 lcd_printf("Now updating ...");
frontispiece 20:4bb2758223fb 104 wait( 4.0 );
frontispiece 20:4bb2758223fb 105 lcd_printf( "led: %s\nfan: %d\n", xi_value_pointer_str( led_ctl ), xi_get_value_i32( fan_ctl ) );
frontispiece 20:4bb2758223fb 106
frontispiece 20:4bb2758223fb 107 switch( xi_get_value_i32( fan_ctl ) ) {
frontispiece 20:4bb2758223fb 108 case 0:
frontispiece 20:4bb2758223fb 109 fan = 0;
frontispiece 20:4bb2758223fb 110 break;
frontispiece 20:4bb2758223fb 111 case 1:
frontispiece 20:4bb2758223fb 112 fan = 1;
frontispiece 20:4bb2758223fb 113 break;
frontispiece 20:4bb2758223fb 114 }
frontispiece 20:4bb2758223fb 115
frontispiece 20:4bb2758223fb 116 if( strcmp( xi_value_pointer_str( led_ctl ), "RED" ) == 0 ) {
frontispiece 20:4bb2758223fb 117 r = 0;
frontispiece 20:4bb2758223fb 118 g = 1;
frontispiece 20:4bb2758223fb 119 b = 1;
frontispiece 20:4bb2758223fb 120 } else if( strcmp( xi_value_pointer_str( led_ctl ), "GREEN" ) == 0 ) {
frontispiece 20:4bb2758223fb 121 r = 1;
frontispiece 20:4bb2758223fb 122 g = 0;
frontispiece 20:4bb2758223fb 123 b = 1;
frontispiece 20:4bb2758223fb 124 } else if( strcmp( xi_value_pointer_str( led_ctl ), "BLUE" ) == 0 ) {
frontispiece 20:4bb2758223fb 125 r = 1;
frontispiece 20:4bb2758223fb 126 g = 1;
frontispiece 20:4bb2758223fb 127 b = 0;
frontispiece 20:4bb2758223fb 128 } else { /* OFF */
frontispiece 20:4bb2758223fb 129 r = 1;
frontispiece 20:4bb2758223fb 130 g = 1;
frontispiece 20:4bb2758223fb 131 b = 1;
frontispiece 20:4bb2758223fb 132 }
frontispiece 20:4bb2758223fb 133
frontispiece 20:4bb2758223fb 134 wait( 5.0 );
frontispiece 20:4bb2758223fb 135 progress_led = 0;
xively 0:efdea27c3b81 136 }
Ilya Dmitrichenko 6:9e4f4a8c1829 137 }