Changeset 5202e8d in pyramid
- Timestamp:
- 10/11/13 14:30:12 (6 years ago)
- Branches:
- master
- Children:
- 85e090e
- Parents:
- f1b827c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/Puzzlebox_Pyramid/Puzzlebox_Pyramid.ino
rf1b827c r5202e8d 65 65 char _command; 66 66 byte _attention_threshold = 67; //treshold for launching Orbit helicopter 67 68 // EEG 69 int eegSignal = 0; 70 int eegAttention = 0; 71 int eegMeditation = 0; 67 72 68 73 // Operation mode … … 155 160 Serial.begin(115200); 156 161 157 158 162 // Android ADK 159 163 delay(500); 160 164 acc.powerOn(); 161 delay(2000); 165 166 167 ////////Orbit Flight/////////// 168 //initialize all timers except for 0, to save time keeping functions 169 InitTimersSafe(); 170 171 //sets the IR_frequency for the specified pin 172 bool success = SetPinFrequencySafe(IR, IR_frequency); 173 174 //if the pin IR_frequency was set successfully, turn pin 13 on 175 if (success) { 176 Serial.println("INFO: PWM pin frequency set"); 177 } 178 179 /////////////RGB//////////////// 180 Wire.begin(); // join i2c bus as master (address optional for master) 181 182 183 setStartScreen(); 184 162 185 163 186 if (acc.isConnected()) { 164 187 modeADK = true; 165 188 Serial.println("INFO: ADK connection detected, setting modeADK"); 166 } 167 168 ////////Orbit Flight/////////// 169 //initialize all timers except for 0, to save time keeping functions 170 InitTimersSafe(); 171 172 //sets the IR_frequency for the specified pin 173 bool success = SetPinFrequencySafe(IR, IR_frequency); 174 175 //if the pin IR_frequency was set successfully, turn pin 13 on 176 if(success) { 177 Serial.println("Set PWM pin frequency SUCCESS"); 178 } 179 180 /////////////RGB//////////////// 181 Wire.begin(); // join i2c bus as master (address optional for master) 182 183 189 setColorWheel(255, 0, 0); // red 190 } 191 192 184 193 //////////Bluetooth/////////// 185 194 if (! modeADK) { 186 setupBlueToothConnection(); 195 196 delay(500); 197 198 // setupBlueToothConnection(); 187 199 188 200 //wait 1s and flush the serial buffer 189 setColorWheel(0,0,255);201 190 202 delay(1000); 191 203 Serial.flush(); //delete? … … 283 295 } 284 296 285 else if (Serial1.available()) {286 // modeBluetooth = true;287 Serial.println("INFO: Bluetooth input received, setting modeBluetooth");288 }289 290 297 else if (acc.isConnected()) { 291 298 modeADK = true; 299 Serial1.end(); 292 300 Serial.println("INFO: ADK connection detected, setting modeADK"); 301 setColorWheel(255, 0, 0); // red 302 } 303 304 else if (Serial1.available()) { 305 modeBluetooth = true; 306 Serial.println("INFO: Bluetooth input received, setting modeBluetooth"); 293 307 } 294 308 … … 369 383 lastReceivedPacket = millis(); 370 384 Serial.print("\n"); 385 371 386 387 if (poorQuality == 200) 388 setColorWheel(0,255,0); // Green 389 390 372 391 //Update RGB Panel when received data from MindWave Mobile 373 392 int att, med; … … 426 445 427 446 void setupBlueToothConnection() { 447 448 setColorWheel(0,0,255); // Blue 428 449 429 450 Serial1.begin(38400); //Set Bluetooth Module BaudRate (for communicating to ADK) to default baud rate 38400 … … 445 466 if(digitalRead(BUTTON_PIN)==0){ //if needs pair 446 467 //update RGB Panel, Red Indicates it's pairing new headset 468 setColorWheel(0,0,0); // Black 447 469 RGB_Panel[5][0]=255; 448 470 RGB_Panel[5][1]=0; … … 508 530 Serial1.print("\r\n+STAUTO=1\r\n");// Permit Auto-connection 509 531 //update bottom RGB LED to blue 532 setColorWheel(0,0,0); // Black 510 533 RGB_Panel[5][0]=0; 511 534 RGB_Panel[5][1]=0; … … 622 645 623 646 } // sendFrame 647 648 649 // ################################################################ 650 651 int calculateMeter(int value) { 652 653 int result = 0; 654 655 if (value == 0) 656 result = 0; 657 else if (value <= 20) 658 result = 1; 659 else if (value <= 40) 660 result = 2; 661 else if (value <= 60) 662 result = 3; 663 else if (value <= 80) 664 result = 4; 665 else if (value <= 100) 666 result = 5; 667 668 return(result); 669 670 } // calculateMeter 671 672 673 // ################################################################ 674 675 void updateFrameADK() { 676 677 // update RGB_Panel[][] here to set next Frame you want to send 678 // For Example: 679 // RGB_Panel[0][0]=0; 680 // RGB_Panel[0][1]=0; 681 // RGB_Panel[0][2]=255; 682 // will update the LED on 1 o'clock position to be blue. 683 684 // This following code simulates when you wear a headset. 685 // RGB_Panel[5][0]=0; 686 // RGB_Panel[5][1]=255; 687 // RGB_Panel[5][2]=0; 688 689 // int attention=random(0,7); //generates 0~6 690 // int meditation=random(0,7); 691 692 693 int attention = calculateMeter(eegAttention); 694 int meditation = calculateMeter(eegMeditation); 695 696 697 for(int i=6; i<=6+attention; i++){ 698 RGB_Panel[i][0]=255; 699 RGB_Panel[i][1]=0; 700 RGB_Panel[i][2]=0; 701 } 702 703 if (meditation==6){ 704 RGB_Panel[11][0]=0; 705 RGB_Panel[11][1]=0; 706 RGB_Panel[11][2]=255; 707 } 708 709 for(int i=4; i>=4-meditation; i--){ 710 RGB_Panel[i][0]=0; 711 RGB_Panel[i][1]=0; 712 RGB_Panel[i][2]=255; 713 } 714 715 if (attention==6) 716 RGB_Panel[11][0]=255; 717 718 for(int i=6+attention; i<=11; i++){ 719 RGB_Panel[i][0]=0; 720 RGB_Panel[i][1]=0; 721 RGB_Panel[i][2]=0; 722 } 723 724 for(int i=4-meditation; i>=0; i--){ 725 RGB_Panel[i][0]=0; 726 RGB_Panel[i][1]=0; 727 RGB_Panel[i][2]=0; 728 } 729 730 } // updateFrame 624 731 625 732 … … 872 979 } 873 980 874 sendFrame(1000); 981 sendFrame(0); 982 983 } 984 985 986 // ################################################################ 987 988 void setStartScreen() { 989 990 // White 991 RGB_Panel[11][0]=255; 992 RGB_Panel[11][1]=255; 993 RGB_Panel[11][2]=255; 994 995 RGB_Panel[3][0]=255; 996 RGB_Panel[3][1]=255; 997 RGB_Panel[3][2]=255; 998 999 RGB_Panel[7][0]=255; 1000 RGB_Panel[7][1]=255; 1001 RGB_Panel[7][2]=255; 1002 1003 // Red 1004 for (int hour=0; hour < 3; hour++) { 1005 RGB_Panel[hour][0]=255; 1006 RGB_Panel[hour][1]=0; 1007 RGB_Panel[hour][2]=0; 1008 } 1009 1010 // Green 1011 for (int hour=4; hour < 7; hour++) { 1012 RGB_Panel[hour][0]=0; 1013 RGB_Panel[hour][1]=255; 1014 RGB_Panel[hour][2]=0; 1015 } 1016 1017 // Blue 1018 for (int hour=8; hour < 11; hour++) { 1019 RGB_Panel[hour][0]=0; 1020 RGB_Panel[hour][1]=0; 1021 RGB_Panel[hour][2]=255; 1022 } 1023 1024 sendFrame(0); 875 1025 876 1026 } … … 932 1082 // Android ADK 933 1083 934 Serial.println("parseADK()");935 936 1084 if (acc.isConnected()) { 937 1085 938 Serial.println("acc.isConnected()");939 940 1086 int len = acc.read(msg, sizeof(msg), 1); 941 1087 942 // if (! modeADK) 943 // Serial.println("INFO: ADK connection detected, setting modeADK"); 944 // modeADK = true; 945 946 947 // Serial.println("len: ", len); 948 1088 if (! modeADK) { 1089 Serial.println("INFO: ADK connection detected, setting modeADK"); 1090 modeADK = true; 1091 } 949 1092 950 1093 // Action taken by Arduino is tied to the message it receives from Android 951 1094 952 // RGB_Panel[11][0]=255; 953 // RGB_Panel[11][1]=255; 954 // RGB_Panel[11][2]=128; 955 // 956 // RGB_Panel[0][0]=255; 957 // RGB_Panel[0][1]=255; 958 // RGB_Panel[0][2]=128; 959 // 960 // RGB_Panel[1][0]=255; 961 // RGB_Panel[1][1]=255; 962 // RGB_Panel[1][2]=128; 963 964 // setColorWheel(255, 0, 255); // purple 965 setColorWheel(255, 0, 0); // red 966 967 sendFrame(1000); 968 1095 if (len > 0) { 1096 if (msg[0] == 0x1) { 1097 // Reserved 1098 } 1099 else if(msg[0] == 0x2) { 1100 // Reserved 1101 } 1102 else if (msg[0] == 0x3) { 1103 // Reserved 1104 } 1105 1106 // EEG Signal 1107 else if (msg[0] == 0x4) { 1108 eegSignal = 0; 1109 if (msg[1] == 0x1) { 1110 eegSignal = 10; 1111 } else if (msg[1] == 0x2) { 1112 eegSignal = 20; 1113 } else if (msg[1] == 0x3) { 1114 eegSignal = 30; 1115 } else if (msg[1] == 0x4) { 1116 eegSignal = 40; 1117 } else if (msg[1] == 0x5) { 1118 eegSignal = 50; 1119 } else if (msg[1] == 0x6) { 1120 eegSignal = 60; 1121 } else if (msg[1] == 0x7) { 1122 eegSignal = 70; 1123 } else if (msg[1] == 0x8) { 1124 eegSignal = 80; 1125 } else if (msg[1] == 0x9) { 1126 eegSignal = 90; 1127 } else { 1128 eegSignal = 100; 1129 } 1130 } 1131 1132 1133 // EEG Attention 1134 else if (msg[0] == 0x5) { 1135 eegAttention = 0; 1136 if (msg[1] == 0x1) { 1137 eegAttention = 10; 1138 } else if (msg[1] == 0x2) { 1139 eegAttention = 20; 1140 } else if (msg[1] == 0x3) { 1141 eegAttention = 30; 1142 } else if (msg[1] == 0x4) { 1143 eegAttention = 40; 1144 } else if (msg[1] == 0x5) { 1145 eegAttention = 50; 1146 } else if (msg[1] == 0x6) { 1147 eegAttention = 60; 1148 } else if (msg[1] == 0x7) { 1149 eegAttention = 70; 1150 } else if (msg[1] == 0x8) { 1151 eegAttention = 80; 1152 } else if (msg[1] == 0x9) { 1153 eegAttention = 90; 1154 } else { 1155 eegAttention = 100; 1156 } 1157 } 1158 1159 1160 // EEG Meditation 1161 else if (msg[0] == 0x6) { 1162 eegMeditation = 0; 1163 if (msg[1] == 0x1) { 1164 eegMeditation = 10; 1165 } else if (msg[1] == 0x2) { 1166 eegMeditation = 20; 1167 } else if (msg[1] == 0x3) { 1168 eegMeditation = 30; 1169 } else if (msg[1] == 0x4) { 1170 eegMeditation = 40; 1171 } else if (msg[1] == 0x5) { 1172 eegMeditation = 50; 1173 } else if (msg[1] == 0x6) { 1174 eegMeditation = 60; 1175 } else if (msg[1] == 0x7) { 1176 eegMeditation = 70; 1177 } else if (msg[1] == 0x8) { 1178 eegMeditation = 80; 1179 } else if (msg[1] == 0x9) { 1180 eegMeditation = 90; 1181 } else { 1182 eegMeditation = 100; 1183 } 1184 } 1185 1186 1187 // updateFrame(eegAttention, eegMeditation, eegSignal); 1188 updateFrameADK(); 1189 sendFrame(1000); 1190 1191 1192 } // len 1193 else { 1194 // setColorWheel(255, 0, 0); // red 1195 delay(10); //cycle(); 1196 } 969 1197 } // if acc.isConnected() 970 1198 … … 983 1211 984 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
Note: See TracChangeset
for help on using the changeset viewer.