Changeset f1b827c in pyramid
- Timestamp:
- 10/11/13 13:06:13 (7 years ago)
- Branches:
- master
- Children:
- 5202e8d
- Parents:
- 94b751c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/Puzzlebox_Pyramid/Puzzlebox_Pyramid.ino
r94b751c rf1b827c 28 28 Original Author: Hao Zhang <hz@puzzlebox.info> 29 29 30 Last Modified 2013-10- 0930 Last Modified 2013-10-10 31 31 by Steve Castellotti <sc@puzzlebox.info> 32 32 … … 36 36 #include <PWM.h> //For sending 38kHz Infrared to fly Orbit helicopter 37 37 38 39 #define DEBUG_OUTPUT 0 // 1 for debug, 2 for verbose 40 41 42 byte _IR_period = 40; 43 44 45 #define BUTTON_PIN 4 46 /////////////Orbit Flight///////////// 38 // ADK 39 #include <Max3421e.h> 40 #include <Usb.h> 41 #include <AndroidAccessory.h> 42 43 44 #define DEBUG_OUTPUT 0 // 1 for debug 45 46 47 // Orbit Flight 47 48 #define IR 6 48 49 #define ON 128 49 50 #define OFF 0 50 51 51 //PWM IR_frequency (in Hz) required by IR 52 // Push Button 53 #define BUTTON_PIN 4 54 55 // PWM IR_frequency (in Hz) required by IR 52 56 #define IR_frequency 38400 53 54 //Global variables for controlling Orbit helicopter 55 //variables start with "_" means global variable 57 byte _IR_period = 40; 58 59 // Global variables for controlling Orbit helicopter 60 // variables start with "_" means global variable 56 61 char _throttle=0; //32~127, default 0 57 62 char _pitch=31; //0~63, default 31 … … 66 71 boolean modeADK = false; 67 72 68 ///////////////MindWave Mobile Protocol/////////// 73 // Android ADK 74 // AndroidAccessory acc( 75 // "puzzlebox", 76 // // "PuzzleboxPyramid", 77 // // "Puzzlebox Pyramid", 78 // // "1.2", 79 // // "http://pyramid.puzzlebox.info", 80 // // "0000000012345678" 81 // "TriggerRemote", 82 // "DemoKit Arduino Board", 83 // "1.0", 84 // "http://www.android.com", 85 // "0000000012345678" 86 // ); 87 88 AndroidAccessory acc( 89 "puzzlebox", 90 "TriggerRemote", 91 "DemoKit Arduino Board", 92 "1.0", 93 "http://www.android.com", 94 "0000000012345678" 95 ); 96 97 byte msg[2]; 98 byte led; 99 100 // MindWave Mobile Protocol 69 101 #define BAUDRATE 57600 70 102 #define DEBUGOUTPUT 0 71 103 #define powercontrol 10 72 104 73 // checksum variables105 // Checksum variables 74 106 byte generatedChecksum = 0; 75 107 byte checksum = 0; 76 108 int payloadLength = 0; 77 byte payloadData[64] = { 78 0 79 }; 109 byte payloadData[64] = { 0 }; 80 110 byte poorQuality = 0; 81 111 byte attention = 0; … … 83 113 byte meditation = 0; 84 114 85 // system variables115 // System variables 86 116 long lastReceivedPacket = 0; 87 117 long lastLoop = 0; … … 89 119 boolean bigPacket = false; 90 120 91 // /////////////Bluetooth Connection with MindWave Mobile/////////////121 // Bluetooth Connection with MindWave Mobile 92 122 String retSymb = "+RTINQ=";//start symble when there's any return 93 123 String slaveName = ";MindWave Mobile";// caution that ';'must be included, and make sure the slave name is right. 94 124 int nameIndex = 0; 95 125 int addrIndex = 0; 96 97 126 String recvBuf; 98 127 String slaveAddr; 99 100 128 String connectCmd = "\r\n+CONN="; 101 129 102 // //////////RGB Panel//////////////130 // RGB Panel 103 131 byte RGB_Panel[12][3] = { 104 132 {0,0,0}, … … 123 151 ///////// 124 152 void setup() { 153 125 154 pinMode(13, OUTPUT); 126 155 Serial.begin(115200); 156 157 158 // Android ADK 159 delay(500); 160 acc.powerOn(); 161 delay(2000); 162 163 if (acc.isConnected()) { 164 modeADK = true; 165 Serial.println("INFO: ADK connection detected, setting modeADK"); 166 } 127 167 128 168 ////////Orbit Flight/////////// … … 140 180 /////////////RGB//////////////// 141 181 Wire.begin(); // join i2c bus as master (address optional for master) 142 182 183 143 184 //////////Bluetooth/////////// 144 setupBlueToothConnection(); 145 //wait 1s and flush the serial buffer 146 delay(1000); 147 Serial.flush();//delete? 148 Serial1.flush(); 185 if (! modeADK) { 186 setupBlueToothConnection(); 187 188 //wait 1s and flush the serial buffer 189 setColorWheel(0,0,255); 190 delay(1000); 191 Serial.flush(); //delete? 192 Serial1.flush(); 193 } 149 194 150 195 … … 167 212 else if (modeSerial) 168 213 parseSerialInput(); 214 215 else if (modeADK) 216 parseADK(); 169 217 170 218 … … 187 235 188 236 if(att_buff>_attention_threshold) { 237 238 // If detected Attention level is above the target threshold 239 // then send the control command to fly the helicopter. 240 // Otherwise send no control frames, which cause the helicopter 241 // to land. 242 189 243 _throttle=85; 190 244 … … 195 249 196 250 Serial1.flush(); 197 251 198 252 } 199 253 … … 207 261 Serial.println(thisLoop); 208 262 #endif 209 263 210 264 lastLoop = millis(); 211 265 212 266 } // if (millis()-lastLoop>_IR_period) 213 267 214 }// Main loop 268 269 } // Main loop 215 270 216 271 … … 221 276 // Determine method for Pyramid control 222 277 223 while ( (! Serial.available()) & (! Serial1.available()) ); 224 225 if (Serial.available()) 226 modeSerial = true; 227 else if (Serial1.available()) 228 modeBluetooth = true; 278 while ( (! Serial.available()) & (! Serial1.available()) & (! acc.isConnected()) ); 279 280 if (Serial.available()) { 281 modeSerial = true; 282 Serial.println("INFO: Serial input command received, setting modeSerial"); 283 } 284 285 else if (Serial1.available()) { 286 // modeBluetooth = true; 287 Serial.println("INFO: Bluetooth input received, setting modeBluetooth"); 288 } 289 290 else if (acc.isConnected()) { 291 modeADK = true; 292 Serial.println("INFO: ADK connection detected, setting modeADK"); 293 } 294 229 295 230 296 } // selectInput … … 239 305 if(ReadOneByte() == 170) { 240 306 241 if (! modeBluetooth)242 Serial.println("INFO: Bluetooth input command received, setting modeBluetooth");243 modeBluetooth = true;307 // if (! modeBluetooth) 308 // Serial.println("INFO: Bluetooth input command received, setting modeBluetooth"); 309 // modeBluetooth = true; 244 310 245 311 if(ReadOneByte() == 170) { … … 796 862 // ################################################################ 797 863 864 void setColorWheel(int red, int green, int blue) { 865 866 for (int hour=0; hour < 12; hour++) { 867 868 RGB_Panel[hour][0]=red; 869 RGB_Panel[hour][1]=green; 870 RGB_Panel[hour][2]=blue; 871 872 } 873 874 sendFrame(1000); 875 876 } 877 878 879 // ################################################################ 880 798 881 ///////////Serial Input/////////// 799 882 void parseSerialInput() { … … 801 884 if (Serial.available() > 0) { 802 885 803 if (! modeSerial) 804 Serial.println("INFO: Serial input command received, setting modeSerial"); 805 modeSerial = true; 886 // if (! modeSerial) 887 // Serial.println("INFO: Serial input command received, setting modeSerial"); 888 // modeSerial = true; 889 890 891 setColorWheel(255, 128, 0); 892 806 893 807 894 // Serial.print("Serial.available(): "); … … 834 921 835 922 sendCode(formCode(_throttle,_yaw,_pitch)); 836 delay(80); // originally 36, 51, 66, 80923 delay(80); // originally 36, 51, 66, 80 837 924 838 925 } // parseSerialInput() 839 926 840 927 841 842 843 844 928 // ################################################################ 929 930 void parseADK() { 931 932 // Android ADK 933 934 Serial.println("parseADK()"); 935 936 if (acc.isConnected()) { 937 938 Serial.println("acc.isConnected()"); 939 940 int len = acc.read(msg, sizeof(msg), 1); 941 942 // if (! modeADK) 943 // Serial.println("INFO: ADK connection detected, setting modeADK"); 944 // modeADK = true; 945 946 947 // Serial.println("len: ", len); 948 949 950 // Action taken by Arduino is tied to the message it receives from Android 951 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 969 } // if acc.isConnected() 970 971 972 } // parseADK 973 974 975 976 977 978 979 980 981 982 983 984
Note: See TracChangeset
for help on using the changeset viewer.