F
Dependencies: mbed Sht31 MAX44009
Revision 6:94a26631ec03, committed 2020-04-23
- Comitter:
- kentwong
- Date:
- Thu Apr 23 14:33:38 2020 +0000
- Parent:
- 5:006e5cf5c2de
- Child:
- 7:e4984029012e
- Commit message:
- hey look
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 13 09:48:01 2020 +0000
+++ b/main.cpp Thu Apr 23 14:33:38 2020 +0000
@@ -10,13 +10,6 @@
I2C i2c(p9, p10); //pins for I2C communication (SDA, SCL)
DigitalOut Batt2SYS(p8);
-//132132134
-//fuckyou
-//fuckme
-//dont fuck me
-InterruptIn BLE_Can_temp(p12);
-
-
DigitalOut BLE_Can_receive(p11); // 0 = can recieve
class RGB{
@@ -47,24 +40,23 @@
TandH THavg;
float luxavg;
+bool wrote=false;
DigitalOut led(LED1);
+char signal[1];
+LocalFileSystem local("local"); //Create the local filesystem under the name "local"
-void flip() {
- led = !led;
-}
-
+
int main()
-{
+{
+
+ //pc.read
pc.baud ( 19200 );
Batt2SYS = 0;
-
- BLE_Can_temp.fall(&flip);
- while(1) {
+
+
+
+ while(1) {
counter = counter%10;
- //BLE_Can_receive = 0;
- //wait_ms(5);
- //pc.printf("counter31 = %d\n", counter);
- //BLE_Can_receive = 1;
{
int sensor_addr = 41 << 1;
char id_regval[1] = {146};
@@ -74,11 +66,9 @@
// Initialize color sensor
-
char timing_register[2] = {129,192};
//char timing_register[2] = {129,0};
i2c.write(sensor_addr,timing_register,2,false);
-
char control_register[2] = {143,0};
char temp[2]={0,0};
//char control_register[2] = {143,3};
@@ -195,19 +185,46 @@
THavg.t = ((THavg.t*(counter) + THdata[counter].t))/(counter+1);
THavg.h = ((THavg.h*(counter) + THdata[counter].h))/(counter+1);
-
+
luxavg = ((luxavg*(counter) + luxdata[counter]))/(counter+1);
}
+ //pc.printf("test");
+ // pc.printf("Shine Like:%s,%d,%d,%d,%d,%3.2f,%3.2f%,%0.001f\n",signal,(int)(RGBavg.C+0.5), (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),THavg.t, THavg.h,luxavg);
BLE_Can_receive = 0;
- wait_ms(5);
- pc.printf("%d,%d,%d,%d,%3.2f,%3.2f%,%0.001f\n",(int)(RGBavg.C+0.5), (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),THavg.t, THavg.h,luxavg);
- counter = counter++;
-
- if (counter == 10) //10 = all element is filled
- allfilled = true;
-
- wait(1);
+ counter++;
+ if (counter == 10){
+ FILE *fp = fopen("/local/out.txt", "a");
+ fprintf(fp, "{%d,%d,%d,%d,%3.2f,%3.2f%,%0.001f},",(int)(RGBavg.C+0.5),
+ (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),THavg.t, THavg.h,luxavg);
+ fclose(fp);
+ allfilled = true;
+ }
BLE_Can_receive = 1;
+ if (wrote){
+ //wait_ms(5);
+ pc.printf("%s,%d,%d,%d,%d,%3.2f,%3.2f%,%0.001f\n",signal,(int)(RGBavg.C+0.5), (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),THavg.t, THavg.h,luxavg);
+ if (counter == 10){ //10 = all element is filled {
+ if (signal[0]=='i'){
+ pc.printf("end");
+ }
+ else if (signal[0]=='a')
+ {
+ pc.printf("aend");
+ }
+ wrote=false;
+ }
+ }
+ else{
+ if(pc.readable() ) {
+ //pc.printf("can read now");
+ led=!led;
+ pc.scanf("%1s", signal);
+ wrote=true;
+ }
+
+ }
+
+
}
}