Created
May 5, 2013 02:24
-
-
Save yoshimax/5519437 to your computer and use it in GitHub Desktop.
Arduino BLE Shield ( http://redbearlab.com/bleshield/ ) + Grove Temperature Sensor ( http://www.seeedstudio.com/wiki/Grove_-_Temperature_Sensor )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Arduino.h> | |
| #include <SPI.h> | |
| #include "ble.h" | |
| #include <Wire.h> | |
| #include "BlinkM_funcs.h" | |
| // blinkM | |
| #define blinkm_addr 0x00 | |
| // temp | |
| #include <math.h> | |
| int a; | |
| float temperature; | |
| int B=3975; //B value of the thermistor | |
| float resistance; | |
| char buf[5] = {0}; | |
| void setup() | |
| { | |
| SPI.setDataMode(SPI_MODE0); | |
| SPI.setBitOrder(LSBFIRST); | |
| SPI.setClockDivider(SPI_CLOCK_DIV16); | |
| SPI.begin(); | |
| ble_begin(); | |
| Serial.begin(57600); | |
| // blinkM Setup | |
| pinMode(13,OUTPUT); | |
| BlinkM_beginWithPower(); | |
| BlinkM_stopScript( blinkm_addr ); // turn off startup script | |
| } | |
| int val; | |
| void loop() | |
| { | |
| while ( ble_available() ){ | |
| if( ble_available()>0){ | |
| val=ble_read(); | |
| } | |
| if(val=='w'){ | |
| BlinkM_fadeToRGB(blinkm_addr,0xff,0xff,0xff); | |
| digitalWrite(13,HIGH); | |
| ble_write('w'); | |
| } | |
| if(val=='r'){ | |
| BlinkM_fadeToRGB(blinkm_addr,0xff,0x00,0x00); | |
| digitalWrite(13,HIGH); | |
| ble_write('r'); | |
| } | |
| if(val=='b'){ | |
| BlinkM_fadeToRGB(blinkm_addr,0x00,0x00,0x00); | |
| digitalWrite(13,LOW); | |
| ble_write('b'); | |
| } | |
| if(val=='t'){ | |
| BlinkM_fadeToRGB(blinkm_addr,0x00,0xff,0x00); | |
| digitalWrite(13,LOW); | |
| a=analogRead(0); | |
| resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor; | |
| temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ; | |
| dtostrf(temperature, 4, 2, buf); | |
| for (int i = 0; i < 5; i++) | |
| ble_write(buf[i]); | |
| } | |
| } | |
| ble_do_events(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment