Graves
Graves the butler will use 3 Arduinos and an Echo Dot to follow you with his head and flap his jaw at you.
Components and supplies
Arduino UNO
Seeed TFT 2.8" v2
Arduino Mega 2560
HC-SR501 Passive Infrared Sensor
Tools and machines
Soldering iron (generic)
Project description
Code
very rough draft
c_cpp
first brainstorm as to how the code might come together
1/* 2Graves multi arduino build 10/2018 3Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 4two arduino uno's 5slave1 arduino uno to sense sound from graves and echo dot to control mouth 6slave2 arduino uno to control passive sensor array and head servo 7 8sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 9 10 analogue pin speaker + 11 \ / (red from speaker) 12 \ / 13 \ / 14 *--------[=]-----------*---------[=]----------* 15 | resistor \ resistor | 16 | \ | 17 |(red with white) \ |to arduino ground (black with white) 18to arduino 5v+ speaker - 19 (black from speaker) 20 21*/ 22 23#include <TFTv2.h> 24#include <SPI.h> 25#include <SeeedTouchScreen.h> 26 27//********************************************************* 28//********************************************************* 29 30// begin void setup 31// begin void setup 32// begin void setup 33// begin void setup 34// begin void setup 35// begin void setup 36// begin void setup 37// begin void setup 38// begin void setup 39// begin void setup 40// begin void setup 41 42void setup() { 43 // need timer to track screen timeout 44 // set screen to on and let timer run to turn off 45 46 47} // void setup() 48 49// end void setup 50// end void setup 51// end void setup 52// end void setup 53// end void setup 54// end void setup 55// end void setup 56// end void setup 57 58//********************************************************* 59//********************************************************* 60 61// begin void loop 62// begin void loop 63// begin void loop 64// begin void loop 65// begin void loop 66// begin void loop 67// begin void loop 68// begin void loop 69 70void loop() { 71 // look for interrupt 72 // 73 74} // void loop() 75 76// end of void loop 77// end of void loop 78// end of void loop 79// end of void loop 80// end of void loop 81// end of void loop 82// end of void loop 83// end of void loop 84// end of void loop 85// end of void loop 86// end of void loop 87// end of void loop 88// end of void loop 89// end of void loop 90 91///////////////////////////////////////////////////////////////////////////////////////////////////////// 92////////////////////////////////////////// /////////////////////////////////////////////////// 93///////////////////////////////////////// functions /////////////////////////////////////////////////// 94//////////////////////////////////////// /////////////////////////////////////////////////// 95///////////////////////////////////////////////////////////////////////////////////////////////////////// 96 97//**************************************************************************************************** 98//**************************************************************************************************** 99 100 101 102//**************************************************************************************************** 103//**************************************************************************************************** 104 105//--------------------------begin arduino master data fetch calls---------------------------------- 106// call slave1 arduino for data 107// call slave2 arduino for data 108//--------------------------end arduino master data fetch calls------------------------------------ 109 110//**************************************************************************************************** 111//**************************************************************************************************** 112 113//--------------------------begin TFT output code---------------------------------- 114// int displaySensorLogs; 115// displaySensorLogs = tftOutputFunction(); 116//--------------------------end TFT output code------------------------------------ 117 118//**************************************************************************************************** 119//**************************************************************************************************** 120 121//-------------------------- begin slave1 data fetch function -------------------------- 122//-------------------------- end slave1 data fetch function -------------------------- 123 124//**************************************************************************************************** 125//**************************************************************************************************** 126 127//-------------------------- begin slave2 data fetch function -------------------------- 128//-------------------------- end slave2 data fetch function ------------------------- 129 130//**************************************************************************************************** 131//**************************************************************************************************** 132 133 134//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 135//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 136//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 137//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 138//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 139 140//**************************************************************************************************** 141//**************************************************************************************************** 142 143//--------------------------- Primary screen maps -------------------------------- 144/* 145 146 147 A)master 148 a)settings 149 -brightness 150 -contrast 151 -screen lock time out 152 b)sensor monitors 153 -pir 154 *report pir detection 155 *report head servo position 156 -sound 157 *sense alexa sound 158 *sense graves sound 159 *report mouth servo position 160 *adjust sensitivity? 161 c)bluetooth 162 -on 163 -off 164 -monitor 165 166 B)slave1 mouth servo 167 a)test button 168 -open 169 -close 170 -push button chicken switch 171 b)sound sensors on/off 172 -alexa sense 173 *on 174 *off 175 *monitor sensor 176 -graves sense 177 *on 178 *off 179 *monitor sensors 180 c)sound sensor status 181 -alexa 182 -graves 183 184 C)slave2 head servo 185 a)pir on/off 186 -on 187 -off 188 b)manual point 189 190*/ 191 192 193//**************************************************************************************************** 194//**************************************************************************************************** 195 196 197 198 199 200 201 202//**************************************************************************************************** 203//**************************************************************************************************** 204 205// fin
24102018 mouth code
c_cpp
New code for the mouth arduino is getting ready to accommodate a new button group and needs threshold adjustment for both graves and echo. new dc bias circuit built with proper resistors thus the need for code adjustment
1/* 224102018 3 4gravesunomouth 5 6graves project 7arduino Uno 8Slave 1 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17 18sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 19 20 analogue pin speaker + 21 \(yellow signal / (red from speaker) 22 10k Ohm \ wire) / 23 resistor \ / 24 *--------/\\/\\/---------*---------/\\/\\/--------* 25 | \ 10k Ohm | 26 | \ resistor | 27 |(red with white) \ |to arduino ground (black with white) 28to arduino 5v+ -)|- 29 \ 100uF 16v 30 \ capacitor 31 \\ 32 \\ 33 speaker - 34 (black from speaker) 35 36*/ 37#include <Servo.h> 38#include <SPI.h> 39 40//---------------------begin declarations----------------------- 41// for servo actions 42Servo mouthServo; 43 44// for gathering and mapping sound data 45int soundPinGraves=A3; // incoming lead from graves dc bias circuit 46int soundPinEcho=A4; // incoming lead from echo dc bias circuit 47int soundDetectedEcho; // stores value from sound pin 48int soundLevelEcho; // converted values that only include 512-1024 49int soundMapEcho; // conversion from 512-1024 to 0-255 50int servoMapEcho; // conversion from 0-255 to 100-70 51int soundDetectedGraves; // stores value from sound pin 52int soundLevelGraves; // converted values that only include 512-1024 53int soundMapGraves; // conversion from 512-1024 to 0-255 54int servoMapGraves; // conversion from 0-255 to 100-70 55 56// communication 57char incomingMouthByte; // for incoming serial data 58char outgoingMouthByte; // for a bit more talkative serial data 59int mouthOnOffNew; // stores mouth state from serial connection 60int mouthOnOffOld; // stores mouth state from serial connection 61int mouthOnOffAdjusted; // value adjusted by 48 for ascii 62 63// for blinking 64const int ledPin = LED_BUILTIN;// the number of the LED pin 65int ledState = LOW; // ledState used to set the LED 66unsigned long previousMillis = 0; // will store last time LED was updated 67//---------------------end declarations----------------------- 68//********************************************************* 69//********************************************************* 70//---------------------begin void setup----------------------- 71//---------------------begin void setup----------------------- 72//---------------------begin void setup----------------------- 73void setup(){ 74 delay(1000); 75 Serial.begin(9600); 76 mouthServo.attach(6); 77 incomingMouthByte = 0; // for incoming serial data 78 outgoingMouthByte = 0; // for a little more talkative serial data 79 mouthOnOffNew = 1; // stores mouth state from serial connection 80 mouthOnOffOld = 1; // stores mouth state from serial connection 81 pinMode(ledPin, OUTPUT); 82 pinMode(soundPinEcho, INPUT); 83 pinMode(soundPinGraves, INPUT); 84} 85//---------------------end void setup----------------------- 86//---------------------end void setup----------------------- 87//---------------------end void setup----------------------- 88//********************************************************** 89//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 90//********************************************************** 91//---------------------begin void loop----------------------- 92//---------------------begin void loop----------------------- 93//---------------------begin void loop----------------------- 94void loop(){ 95 serialDoStuff(); 96 if(mouthOnOffNew == mouthOnOffOld){ 97 if(mouthOnOffNew == 1){ 98 blinkFast(); 99 mouthDoStuffGraves(); 100 mouthDoStuffEcho(); 101 } 102 if(mouthOnOffNew == 2){ 103 mouthDoStuffEcho(); 104 blinkSlow(); 105 } 106 if(mouthOnOffNew == 3){ 107 blinkSlow(); 108 mouthDoStuffGraves(); 109 } 110 if(mouthOnOffNew == 4){ 111 } 112 if(mouthOnOffNew == 5){ 113 } 114 if(mouthOnOffNew == 6){ 115 } 116 if(mouthOnOffNew == 7){ 117 } 118 if(mouthOnOffNew == 8){ 119 } 120 } 121 else if(mouthOnOffNew != mouthOnOffOld){ 122 mouthOnOffNew = mouthOnOffOld; 123 } 124} 125//---------------------end void loop----------------------- 126//---------------------end void loop----------------------- 127//---------------------end void loop----------------------- 128//********************************************************* 129//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 130//********************************************************* 131//---------------------begin serialDoStuff ----------------- 132void serialDoStuff(){ 133 if(Serial.available() > 0){ 134 incomingMouthByte = Serial.read(); 135 mouthOnOffAdjusted = incomingMouthByte - '0'; 136 if(mouthOnOffAdjusted == 1){ 137 Serial.flush(); 138 outgoingMouthByte = 1; 139 Serial.write(outgoingMouthByte); 140 mouthOnOffOld = 1; 141 } 142 else if(mouthOnOffAdjusted == 2){ 143 Serial.flush(); 144 outgoingMouthByte = 2; 145 Serial.write(outgoingMouthByte); 146 mouthOnOffOld = 2; 147 } 148 else if(mouthOnOffAdjusted == 3){ 149 Serial.flush(); 150 outgoingMouthByte = 3; 151 Serial.write(outgoingMouthByte); 152 mouthOnOffOld = 3; 153 } 154 else if(mouthOnOffAdjusted == 4){ 155 Serial.flush(); 156 outgoingMouthByte = 4; 157 Serial.write(outgoingMouthByte); 158 mouthOnOffOld = 4; 159 } 160 else if(mouthOnOffAdjusted == 5){ 161 Serial.flush(); 162 outgoingMouthByte = 5; 163 Serial.write(outgoingMouthByte); 164 mouthOnOffOld = 5; 165 } 166 else if(mouthOnOffAdjusted == 6){ 167 Serial.flush(); 168 outgoingMouthByte = 6; 169 Serial.write(outgoingMouthByte); 170 mouthOnOffOld = 6; 171 } 172 else if(mouthOnOffAdjusted == 7){ 173 Serial.flush(); 174 outgoingMouthByte = 7; 175 Serial.write(outgoingMouthByte); 176 mouthOnOffOld = 7; 177 } 178 else if(mouthOnOffAdjusted == 8){ 179 Serial.flush(); 180 outgoingMouthByte = 8; 181 Serial.write(outgoingMouthByte); 182 mouthOnOffOld = 8; 183 } 184 } 185 Serial.println(analogRead(soundPinGraves)); 186 Serial.print(" "); 187 Serial.println(analogRead(soundPinEcho)); 188// Serial.print("raw LevelGraves "); 189// Serial.print(analogRead(soundPinGraves)); 190// Serial.print("soundLevelGraves "); 191// Serial.println(soundLevelGraves); 192// Serial.print(" servoMapGraves "); 193// Serial.println(servoMapGraves); 194// Serial.print("soundDetectedGraves "); 195// Serial.println(soundDetectedGraves); 196} 197//---------------------end serialDoStuff----------------- 198//********************************************************* 199//********************************************************* 200//---------------------begin mouthDoStuffGraves ------------------- 201 202void mouthDoStuffGraves(){ 203 int soundDetectedGraves; // stores value from sound pin 204 int soundLevelGraves; // converted values that only include 512-1024 205 int servoMapGraves; // conversion from 0-255 to 100-70 206 207 208 soundDetectedGraves = analogRead(soundPinGraves); // capture audio signal from dc bias circuit 209 if(soundDetectedGraves<=512){ // runs when negative amplitude detected 210 soundLevelGraves = (512-soundDetectedGraves+512); // takes numbers below 512 and tacks em on top of 512 to create positive amplitudes 211 } 212 else{ 213 soundLevelGraves = soundDetectedGraves; // stores positive amplitudes 214 } 215 216 servoMapGraves = map(soundLevelGraves, 570, 610, 100, 50); // sound map 0-255 is mapped to truncated and inverted servo sweep 100-70 217 if(soundLevelGraves < 700 ){ 218 if(servoMapGraves < 100){ 219 mouthServo.write(servoMapGraves); 220 } 221 } 222 else{ 223 mouthServo.write(95); 224 } 225 // return soundLevelGraves; 226} 227 228//// ++++++++++++++++++end mouthDoStuffGraves +++++++++++++++++++++++++++++++++ 229//********************************************************* 230//********************************************************* 231//---------------------begin mouthDoStuffEcho ------------------- 232 233void mouthDoStuffEcho(){ 234 int soundDetectedEcho; // stores value from sound pin 235 int soundLevelEcho; // converted values that only include 512-1024 236 int servoMapEcho; // conversion from 0-255 to 100-70 237 238 239 soundDetectedEcho = analogRead(soundPinEcho); // capture audio signal from dc bias circuit 240 if(soundDetectedEcho<=512){ // runs when negative amplitude detected 241 soundLevelEcho = (512-soundDetectedEcho+512); // takes numbers below 512 and tacks em on top of 512 to create positive amplitudes 242 } 243 else{ 244 soundLevelEcho = soundDetectedEcho; // stores positive amplitudes 245 } 246 247 servoMapEcho = map(soundLevelEcho, 570, 610, 100, 50); // sound map 0-255 is mapped to truncated and inverted servo sweep 100-70 248 if(soundLevelEcho < 700 ){ 249 if(servoMapEcho < 100){ 250 mouthServo.write(servoMapEcho); 251 } 252 } 253 else{ 254 mouthServo.write(95); 255 } 256 // return soundLevelEcho; 257} 258 259//// ++++++++++++++++++end mouthDoStuffEcho +++++++++++++++++++++++++++++++++ 260//********************************************************* 261//********************************************************* 262//---------------------begin blink slow------------------- 263void blinkSlow(){ 264unsigned long currentMillis = millis(); 265const long interval1 = 500; 266 267 if(currentMillis - previousMillis >= interval1) { 268 previousMillis = currentMillis; 269 if(ledState == LOW){ 270 ledState = HIGH; 271 } 272 else{ 273 ledState = LOW; 274 } 275 digitalWrite(ledPin, ledState); 276 } 277} 278//---------------------end blink slow------------------- 279//---------------------begin blink fast ------------------- 280void blinkFast(){ 281unsigned long currentMillis = millis(); 282const long interval2 = 75; 283 if(currentMillis - previousMillis >= interval2){ 284 previousMillis = currentMillis; 285 if(ledState == LOW){ 286 ledState = HIGH; 287 } 288 else{ 289 ledState = LOW; 290 } 291 digitalWrite(ledPin, ledState); 292 } 293} 294//---------------------end blink fast ------------------- 295//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 296//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 297//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 298 299
25102018 night mega code PAGES UPDATED!!!
c_cpp
Man, that was tough! All pages updated and coupled to button groups. button groups updated to accommodate backlight timer adjustment
1/* 225102018 3 4gravesmegamaster 5 6graves project 7arduino MEGA 2650 8Master 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17 18sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 19 20 analogue pin speaker + 21 \(yellow signal / (red from speaker) 22 10k Ohm \ wire) / 23 resistor \ / 24 *--------/\\/\\/---------*---------/\\/\\/--------* 25 | \ 10k Ohm | 26 | \ resistor | 27 |(red with white) \ |to arduino ground (black with white) 28to arduino 5v+ -)|- 29 \ 100uF 16v 30 \ capacitor 31 \\ 32 \\ 33 speaker - 34 (black from speaker) 35 36*/ 37//end notes 38//end notes 39//end notes 40//end notes 41//end notes 42//end notes 43 44 45//********************************************************* 46//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 47//********************************************************* 48 49 50//begin declarations 51//begin declarations 52//begin declarations 53//begin declarations 54//begin declarations 55//begin declarations 56//begin declarations 57 58//#include <TFT.h> 59//#include <Servo.h> 60//#include <stdint.h> 61//#include <SD.h> 62#include <TFTv2.h> 63#include <SPI.h> 64#include <SeeedTouchScreen.h> 65//#include <Wire.h> 66 67//const int PIN_SD_CS = 4; // pin of sd card 68 69TouchScreen ts = TouchScreen(XP, YP, XM, YM); 70int zMax; // maximum pressure to detect 71int zMin; // minimum pressure to detect 72 73int buttonPressed; // stores which button was pressed 74unsigned long newButtonTime; // debounce 75unsigned long oldButtonTime; // debounce 76unsigned long buttonTimeDifference; // debounce 77unsigned long debounceTime; // debounce 78int buttonGroup; // sets kinds of buttons on screen 79 80int currentScreen; // identifies current screen by adding x y and z 81int x; // for ones 82int y; // for tens 83int z; // for hundreds 84 85unsigned long backlightTimer; // for backlight timeout 86int backLightState; // status of backlight 1 for on and 0 for off 87unsigned long backlightTimeDifference; 88unsigned long newBacklightTime; 89unsigned long oldBacklightTime; 90 91char incomingMouthByte; 92char outgoingMouthByte; 93int mouthOnOffNew; 94int mouthOnOffOld; 95int mouthOnOffDifference; 96int mouthOnOffAdjusted; // value adjusted by 48 for ascii 97 98char incomingHeadByte; 99char outgoingHeadByte; 100int headOnOffNew; 101int headOnOffOld; 102int headOnOffDifference; 103int headOnOffAdjusted; // value adjusted by 48 for ascii 104 105//end declarations 106//end declarations 107//end declarations 108//end declarations 109//end declarations 110//end declarations 111//end declarations 112//end declarations 113//end declarations 114 115//********************************************************* 116//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 117//********************************************************* 118 119// begin void setup 120// begin void setup 121// begin void setup 122// begin void setup 123// begin void setup 124// begin void setup 125// begin void setup 126// begin void setup 127// begin void setup 128// begin void setup 129// begin void setup 130void setup() { 131Serial.begin(9600); 132Serial1.begin(9600); 133Serial2.begin(9600); 134 oldButtonTime = millis(); 135 newButtonTime = millis(); 136 Tft.TFTinit(); // init TFT library 137 TFT_BL_ON; // turn on the background light 138 backLightState = 1; 139 x = 0; 140 y = 0; 141 z = 0; 142 buttonPressed = 4; 143 buttonGroup = 0; 144 145 incomingHeadByte = 1; 146 outgoingHeadByte = 1; // for a bit more talkative serial data 147 headOnOffNew = 1; // stores head state from serial connection 148 headOnOffOld = 1; // stores head state from serial connection 149 150 151 incomingMouthByte = 0; 152 outgoingMouthByte = 0; // for a bit more talkative serial data 153 mouthOnOffNew = 1; // stores mouth state from serial connection 154 mouthOnOffOld = 1; // stores mouth state from serial connection 155 156 157 //////////////////////////////// 158 //// manually set variables //// 159 //////////////////////////////// 160// \\/ \\/ \\/ \\/ \\/ \\/ 161 162 debounceTime = 1000; // button debounce in milliseconds 163 zMax = 460; // maximum pressure to detect 164 zMin = 100; // minimum pressure to detect 165 166 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 167 168// /\ /\ /\ /\ /\ /\\ 169 //////////////////////////////// 170 //// manually set variables //// 171 //////////////////////////////// 172 173 174 currentScreen = 0; 175 callScreen(); 176 177} //void setup() 178// end void setup 179// end void setup 180// end void setup 181// end void setup 182// end void setup 183// end void setup 184// end void setup 185// end void setup 186 187//********************************************************* 188//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 189//********************************************************* 190 191// begin void loop 192// begin void loop 193// begin void loop 194// begin void loop 195// begin void loop 196// begin void loop 197// begin void loop 198// begin void loop 199// begin void loop 200// begin void loop 201// begin void loop 202// begin void loop 203// begin void loop 204// begin void loop 205 206void loop() { 207 208 tftBacklightTimeout(); // check time and turn off backlight 209 210 if(buttonGroup == 0){ // most regular pages 211 tftButtonGroup0(); // gather information from touch screen touches 212 buttonTimeDifference = newButtonTime - oldButtonTime; 213 if(debounceTime < buttonTimeDifference){ 214 whatScreen(); 215 callScreen(); 216 oldButtonTime = newButtonTime; 217 showStuff(); // serial prints 218 tftDisplay(); // display x y coordinates on tft display 219 } 220 } 221 if(buttonGroup == 1){ // on off buttons 222 tftButtonGroup1(); // gather information from touch screen touches 223 buttonTimeDifference = newButtonTime - oldButtonTime; 224 if(debounceTime < buttonTimeDifference){ 225 whatScreen(); 226 callScreen(); 227 oldButtonTime = newButtonTime; 228 showStuff(); // serial prints 229 tftDisplay(); // display x y coordinates on tft display 230 mouthUnoTxRx(); 231 } 232 } 233 if(buttonGroup == 2){ // head buttons 234 tftButtonGroup2(); // gather information from touch screen touches 235 buttonTimeDifference = newButtonTime - oldButtonTime; 236 if(debounceTime < buttonTimeDifference){ 237 whatScreen(); 238 callScreen(); 239 oldButtonTime = newButtonTime; 240 showStuff(); // serial prints 241 tftDisplay(); // display x y coordinates on tft display 242 headUnoTxRx(); 243 } 244 } 245 if(buttonGroup == 3){ // head buttons 246 tftButtonGroup3(); // gather information from touch screen touches 247 buttonTimeDifference = newButtonTime - oldButtonTime; 248 if(debounceTime < buttonTimeDifference){ 249 whatScreen(); 250 callScreen(); 251 oldButtonTime = newButtonTime; 252 showStuff(); // serial prints 253 tftDisplay(); // display x y coordinates on tft display 254 } 255 } 256 257 258} //void loop() 259 260// end of void loop 261// end of void loop 262// end of void loop 263// end of void loop 264// end of void loop 265// end of void loop 266// end of void loop 267// end of void loop 268// end of void loop 269// end of void loop 270// end of void loop 271// end of void loop 272// end of void loop 273// end of void loop 274// end of void loop 275 276//**************************************************************************************************** 277//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 278//**************************************************************************************************** 279///////////////////////////////////////////////////////////////////////////////////////////////////////// 280///////////////////////////////////////// functions /////////////////////////////////////////////////// 281///////////////////////////////////////////////////////////////////////////////////////////////////////// 282//**************************************************************************************************** 283//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 284//**************************************************************************************************** 285 286//--------------------------begin tftBacklightTimeout---------------------------------- 287void tftBacklightTimeout(){ 288 newBacklightTime = millis(); 289 if(backLightState = 0){ 290 backlightTimeDifference = newBacklightTime - oldBacklightTime; 291 if(backlightTimer > backlightTimeDifference){ 292 backlightTimeDifference = newBacklightTime - oldBacklightTime; 293 TFT_BL_ON; // turn on the background light 294 backLightState = 1; 295 oldBacklightTime = millis(); 296 } 297 } 298 if(backLightState = 1){ 299 backlightTimeDifference = newBacklightTime - oldBacklightTime; 300 if(backlightTimer < backlightTimeDifference){ 301 backlightTimeDifference = newBacklightTime - oldBacklightTime; 302 TFT_BL_OFF; // turn off the background light 303 backLightState = 0; 304 oldBacklightTime = millis(); 305 } 306 } 307} 308//--------------------------end tftBacklightTimeout---------------------------------- 309 310//**************************************************************************************************** 311//**************************************************************************************************** 312 313//--------------------------begin tftButtonGroup0---------------------------------- 314//--------------------------begin tftButtonGroup0---------------------------------- 315//--------------------------begin tftButtonGroup0---------------------------------- 316//--------------------------begin tftButtonGroup0---------------------------------- 317int tftButtonGroup0(){ 318 Point p = ts.getPoint(); 319 if(zMin<p.z && p.z<zMax){ 320 TFT_BL_ON; // turn on the background light 321 backLightState = 1; 322 oldBacklightTime = millis(); 323 newButtonTime = millis(); 324 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 325 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 326//Button 1 327 if(75<p.x && p.x<140){ 328 if(100<p.y && p.y<164){ 329 buttonPressed = 1; 330 } 331//Button 2 332 if(164<p.y && p.y<240){ 333 buttonPressed = 2; 334 } 335//Button 3 336 if(240<p.y && p.y<310){ 337 buttonPressed = 3; 338 } 339 } 340 } 341//Button 4 342 if(10<p.x && p.x<75){ 343 if(100<p.y && p.y<240){ 344 buttonPressed = 4; 345 } 346 } 347}//void tftButtonGroup0 348//--------------------------end tftButtonGroup0 code---------------------------------- 349//--------------------------end tftButtonGroup0 code---------------------------------- 350//--------------------------end tftButtonGroup0 code---------------------------------- 351//--------------------------end tftButtonGroup0 code---------------------------------- 352//--------------------------end tftButtonGroup0 code---------------------------------- 353//**************************************************************************************************** 354//**************************************************************************************************** 355 356//--------------------------begin tftButtonGroup1---------------------------------- 357//--------------------------begin tftButtonGroup1---------------------------------- 358//--------------------------begin tftButtonGroup1---------------------------------- 359//--------------------------begin tftButtonGroup1---------------------------------- 360int tftButtonGroup1(){ // for mouth 361buttonPressed = 0; 362 Point p = ts.getPoint(); 363 if(zMin<p.z && p.z<zMax){ 364 TFT_BL_ON; // turn on the background light 365 backLightState = 1; 366 oldBacklightTime = millis(); 367 newButtonTime = millis(); 368 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 369 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 370//Button 1 371 if(75<p.x && p.x<140){ 372 if(100<p.y && p.y<164){ 373 mouthOnOffNew = 1; // on 374 Serial.print("mouthOnOffNew set to "); 375 Serial.println(mouthOnOffNew); 376 } 377//Button 2 378 if(164<p.y && p.y<240){ 379 mouthOnOffNew = 2; // off 380 Serial.print("mouthOnOffNew set to "); 381 Serial.println(mouthOnOffNew); 382 } 383//Button 3 384// if(240<p.y && p.y<310){ 385// mouthOnOffNew = 3; // off 386// Serial.print("mouthOnOffNew set to "); 387// Serial.println(mouthOnOffNew); 388// } 389 } 390 } 391//Button 4 392 if(10<p.x && p.x<75){ 393 if(100<p.y && p.y<240){ 394 buttonPressed = 4; 395 buttonGroup = 0; 396 } 397 } 398}//void tftButtonGroup1 399//--------------------------end tftButtonGroup1 code---------------------------------- 400//--------------------------end tftButtonGroup1 code---------------------------------- 401//--------------------------end tftButtonGroup1 code---------------------------------- 402//--------------------------end tftButtonGroup1 code---------------------------------- 403//--------------------------end tftButtonGroup1 code---------------------------------- 404//**************************************************************************************************** 405//**************************************************************************************************** 406 407//--------------------------begin tftButtonGroup2---------------------------------- 408//--------------------------begin tftButtonGroup2---------------------------------- 409//--------------------------begin tftButtonGroup2---------------------------------- 410//--------------------------begin tftButtonGroup2---------------------------------- 411int tftButtonGroup2(){ // for mouth 412buttonPressed = 0; 413 Point p = ts.getPoint(); 414 if(zMin<p.z && p.z<zMax){ 415 TFT_BL_ON; // turn on the background light 416 backLightState = 1; 417 oldBacklightTime = millis(); 418 newButtonTime = millis(); 419 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 420 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 421//Button 1 422 if(75<p.x && p.x<140){ 423 if(100<p.y && p.y<164){ 424 headOnOffNew = 1; // on 425 Serial.print("headOnOffNew set to "); 426 Serial.println(headOnOffNew); 427 } 428//Button 2 429 if(164<p.y && p.y<240){ 430 headOnOffNew = 2; // off 431 Serial.print("headOnOffNew set to "); 432 Serial.println(headOnOffNew); 433 } 434//Button 3 435// if(240<p.y && p.y<310){ 436// buttonPressed = 3; 437// } 438 } 439 } 440//Button 4 441 if(10<p.x && p.x<75){ 442 if(100<p.y && p.y<240){ 443 buttonPressed = 4; 444 buttonGroup = 0; 445 } 446 } 447}//void tftButtonGroup2 448//--------------------------end tftButtonGroup2 code---------------------------------- 449//--------------------------end tftButtonGroup2 code---------------------------------- 450//--------------------------end tftButtonGroup2 code---------------------------------- 451//--------------------------end tftButtonGroup2 code---------------------------------- 452//--------------------------end tftButtonGroup2 code---------------------------------- 453//**************************************************************************************************** 454//**************************************************************************************************** 455//--------------------------begin tftButtonGroup3---------------------------------- 456//--------------------------begin tftButtonGroup3---------------------------------- 457//--------------------------begin tftButtonGroup3---------------------------------- 458//--------------------------begin tftButtonGroup3---------------------------------- 459int tftButtonGroup3(){ // for tft backlight 460buttonPressed = 0; 461 Point p = ts.getPoint(); 462 if(zMin<p.z && p.z<zMax){ 463 TFT_BL_ON; // turn on the background light 464 backLightState = 1; 465 oldBacklightTime = millis(); 466 newButtonTime = millis(); 467 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 468 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 469 if(75<p.x && p.x<140){ 470//Button 1 471 if(100<p.y && p.y<164){ 472 backlightTimer = 120000; 473 } 474//Button 2 475 if(164<p.y && p.y<240){ 476 backlightTimer = 15000; 477 } 478//Button 3 479 if(240<p.y && p.y<310){ 480 buttonPressed = 3; 481 backlightTimer = 5000; 482 } 483 } 484 } 485//Button 4 486 if(10<p.x && p.x<75){ 487 if(100<p.y && p.y<240){ 488 buttonPressed = 4; 489 buttonGroup = 0; 490 } 491 } 492}//void tftButtonGroup3 493//--------------------------end tftButtonGroup3 code---------------------------------- 494//--------------------------end tftButtonGroup3 code---------------------------------- 495//--------------------------end tftButtonGroup3 code---------------------------------- 496//--------------------------end tftButtonGroup3 code---------------------------------- 497//--------------------------end tftButtonGroup3 code---------------------------------- 498//**************************************************************************************************** 499//**************************************************************************************************** 500 501//--------------------------begin mouthUnoTxRx---------------------------------- 502 503void mouthUnoTxRx(){ 504 if(mouthOnOffNew != mouthOnOffOld){ 505 Serial.println("starting txrx"); 506 if(mouthOnOffNew == 1){ 507 Serial.println("Starting tx"); 508 Serial1.flush(); 509 Serial1.write('1'); 510 mouthOnOffOld = 1; 511//begin rx 512 Serial.println("Starting rx"); 513 514 delay(10); // tweak delay to accomodate uno 515 516 // use a serial available after flush funtion while or for loop or interrrupt or somethin 517 incomingMouthByte = Serial1.read(); 518 Serial1.flush(); 519 mouthOnOffAdjusted = incomingMouthByte; 520 Serial.print("mouthOnOffAdjusted should be 1: "); 521 Serial.println(mouthOnOffAdjusted); 522 } 523 if(mouthOnOffNew == 2){ 524 Serial.println("Starting tx"); 525 Serial1.flush(); 526 Serial1.write('2'); 527 mouthOnOffOld = 2; 528//begin rx 529 Serial.println("Starting rx"); 530 531 delay(10); // tweak delay to accomodate uno 532 533 incomingMouthByte = Serial1.read(); 534 Serial1.flush(); 535 mouthOnOffAdjusted = incomingMouthByte; 536 Serial.print("mouthOnOffAdjusted should be 2: "); 537 Serial.println(mouthOnOffAdjusted); 538 } 539 if(mouthOnOffNew == 3){ 540 Serial.println("Starting tx"); 541 Serial1.flush(); 542 Serial1.write('3'); 543 mouthOnOffOld = 3; 544//begin rx 545 Serial.println("Starting rx"); 546 547 delay(10); // tweak delay to accomodate uno 548 549 // use a serial available after flush funtion while or for loop or interrrupt or somethin 550 incomingMouthByte = Serial1.read(); 551 Serial1.flush(); 552 mouthOnOffAdjusted = incomingMouthByte; 553 Serial.print("mouthOnOffAdjusted should be 3: "); 554 Serial.println(mouthOnOffAdjusted); 555 } 556 if(mouthOnOffNew == 4){ 557 Serial.println("Starting tx"); 558 Serial1.flush(); 559 Serial1.write('4'); 560 mouthOnOffOld = 4; 561//begin rx 562 Serial.println("Starting rx"); 563 564 delay(10); // tweak delay to accomodate uno 565 566 // use a serial available after flush funtion while or for loop or interrrupt or somethin 567 incomingMouthByte = Serial1.read(); 568 Serial1.flush(); 569 mouthOnOffAdjusted = incomingMouthByte; 570 Serial.print("mouthOnOffAdjusted should be 4: "); 571 Serial.println(mouthOnOffAdjusted); 572 } 573 574 575 else if(mouthOnOffAdjusted <= 1 && 4 >= mouthOnOffAdjusted){ 576 Serial.println("error reply wasn't like expected"); 577 Serial.print("instead, the adjusted reply was"); 578 579 delay(10); // tweak delay to accomodate uno 580 581 incomingMouthByte = Serial1.read(); 582 Serial1.flush(); 583 mouthOnOffAdjusted = incomingMouthByte; 584 Serial.print("mouthOnOffAdjusted: "); 585 Serial.println(mouthOnOffAdjusted); 586 } 587 } 588 else if(mouthOnOffOld = mouthOnOffNew){ 589 } 590 Serial.flush(); 591 Serial1.flush(); 592} 593 594//--------------------------end mouthUnoTxRx -------------------------------------- 595//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 596//--------------------------begin headUnoTxRx---------------------------------- 597 598void headUnoTxRx(){ 599 if(headOnOffNew != headOnOffOld){ 600 Serial.println("starting txrx"); 601 if(headOnOffNew == 1){ 602 Serial.println("Starting tx"); 603 Serial2.flush(); 604 Serial2.write('1'); 605 headOnOffOld = 1; 606//begin rx 607 Serial.println("Starting rx"); 608 609 delay(10); // tweak delay to accomodate uno 610 611 // use a serial available after flush funtion while or for loop or interrrupt or somethin instead of delay 612 incomingHeadByte = Serial2.read(); 613 Serial2.flush(); 614 headOnOffAdjusted = incomingHeadByte; 615 Serial.print("headOnOffAdjusted should be 1: "); 616 Serial.println(headOnOffAdjusted); 617 } 618 if(headOnOffNew == 2){ 619 Serial.println("Starting tx"); 620 Serial2.flush(); 621 Serial2.write('2'); 622 headOnOffOld = 2; 623//begin rx 624 Serial.println("Starting rx"); 625 626 delay(10); // tweak delay to accomodate uno 627 628 incomingHeadByte = Serial2.read(); 629 Serial2.flush(); 630 headOnOffAdjusted = incomingHeadByte; 631 Serial.print("headOnOffAdjusted should be 2: "); 632 Serial.println(headOnOffAdjusted); 633 } 634 else if(headOnOffAdjusted != 1 && headOnOffAdjusted != 2){ 635 Serial.println("error reply wasn't like expected"); 636 Serial.print("instead, the adjusted reply was"); 637 638 delay(10); // tweak delay to accomodate uno 639 640 incomingHeadByte = Serial2.read(); 641 Serial2.flush(); 642 headOnOffAdjusted = incomingHeadByte; 643 Serial.print("headOnOffAdjusted: "); 644 Serial.println(headOnOffAdjusted); 645 } 646 } 647 else if(headOnOffOld = headOnOffNew){ 648 } 649 Serial.flush(); 650 Serial2.flush(); 651} 652 653//--------------------------end headUnoTxRx -------------------------------------- 654//**************************************************************************************************** 655//**************************************************************************************************** 656 657//--------------------------begin tftDisplay code---------------------------------- 658void tftDisplay(){ 659 Point p = ts.getPoint(); 660 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 661 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 662 663 Tft.fillRectangle(70, 100, 60, 30, BLACK); 664 Tft.drawNumber((buttonGroup), 70, 100, 3, GREEN); 665 Tft.fillRectangle(140, 100, 60, 30, BLACK); 666 Tft.drawNumber((mouthOnOffNew), 140, 100, 3, GREEN); 667 Tft.fillRectangle(160, 100, 60, 30, BLACK); 668 Tft.drawNumber((headOnOffNew), 160, 100, 3, GREEN); 669 Tft.fillRectangle(0, 225, 60, 30, BLACK); 670 Tft.drawNumber((p.x), 0, 225, 3, GREEN); 671 Tft.fillRectangle(180, 225, 60, 30, BLACK); 672 Tft.drawNumber((p.y), 180, 225, 3, GREEN); 673 Tft.fillRectangle(100, 225, 60, 30, BLACK); 674 Tft.drawNumber((buttonPressed), 100, 225, 3, GREEN); 675 Tft.fillRectangle(120, 290, 60, 30, BLACK); 676 Tft.drawNumber((currentScreen), 120, 290, 3, GREEN); 677 678 679}// void tftDisplay 680//--------------------------end tftDisplay code------------------------------------ 681 682//**************************************************************************************************** 683//**************************************************************************************************** 684 685//-------------------------- begin mouth on off function -------------------------- 686//-------------------------- end mouth on off function -------------------------- 687 688//**************************************************************************************************** 689//**************************************************************************************************** 690 691//-------------------------- begin head on off function -------------------------- 692//-------------------------- end head on off function ------------------------- 693 694//**************************************************************************************************** 695//**************************************************************************************************** 696 697//-------------------------- begin serial display function -------------------------- 698void showStuff(){ 699 Serial.println("------/ last update /-------"); 700// Serial.println("------begin display-------"); 701 Serial.print("buttonPressed "); 702 Serial.println(buttonPressed); 703 Serial.print("x "); 704 Serial.println(x); 705 Serial.print("y "); 706 Serial.println(y); 707 Serial.print("z "); 708 Serial.println(z); 709 Serial.print("currentScreen "); 710 Serial.println(currentScreen); 711// Serial.println("-------end display--------"); 712 Serial.println(""); 713 Serial.println(""); 714 Serial.println(""); 715 } 716//-------------------------- end serial display function ------------------------- 717 718 719//**************************************************************************************************** 720//**************************************************************************************************** 721 722//--------------------------- Primary screen maps -------------------------------- 723/* 724 725 726 727screen 0000 A)Main Controls 728 729 screen 0001 a)motor controls 730 731 screen 0001 b) Touch Screen Timeout 732 screen 0011 -longer 733 screen 0011 -shorter 734 screen 0011 -reset 735 736 screen 0001 c)sensor monitors 737 screen 0021 -head reports 738 screen 0121 *report pir detection 739 screen 0121 *report pot position 740 screen 0021 -mouth reports 741 screen 0221 *graves sense 742 screen 0221 *echo sense 743 screen 0221 *report mouth servo position 744// screen 0221 *adjust sensitivity? 745 746screen 0000 B)Mouth Control 747 748 screen 0002 a)test button 749 screen 0012 -open 750 screen 0012 -close 751 752 screen 0002 b)sound sensors on/off 753 754 screen 0022 -echo sense 755 screen 0122 *on 756 screen 0122 *off 757 screen 0122 *monitor sensor 758 759 screen 0022 -graves sense 760 screen 0222 *on 761 screen 0222 *off 762 screen 0222 *monitor sensors 763 764 screen 0002 c)sound sensor status 765 screen 0032 -echo 766 screen 0032 -graves 767 768screen 0000 C)Head Control 769 screen 0003 a)head motor on/off 770 screen 0013 -on 771 screen 0013 -off 772 screen 0003 b)manual point 773 screen 0023 -slider 774*/ 775//**************************************************************************************************** 776//**************************************************************************************************** 777//-------------------------- begin whatScreen function ------------------------- 778//-------------------------- begin whatScreen function ------------------------- 779//-------------------------- begin whatScreen function ------------------------- 780//-------------------------- begin whatScreen function ------------------------- 781 782int whatScreen(){ 783 if(x == 0){ 784 if(buttonPressed == 1){ 785 x = x + 1; 786 Serial.println("x + 1"); 787 } 788 if(buttonPressed == 2){ 789 x = x + 2; 790 Serial.println("x + 2"); 791 } 792 if(buttonPressed == 3){ 793 x = x + 3; 794 Serial.println("x + 3"); 795 } 796 if(buttonPressed == 4){ 797 x = 0; 798 Serial.println("x = 0"); 799 } 800 if(buttonPressed == 5){ 801 x = 0; 802 y = 0; 803 z = 0; 804 Serial.println("xyz all 0"); 805 } 806 } 807 else if(x >> 0){ 808 if(y == 0){ 809 if(buttonPressed == 1){ 810 y = y + 10; 811 Serial.println("y + 10"); 812 } 813 if(buttonPressed == 2){ 814 y = y + 20; 815 Serial.println("y + 20"); 816 } 817 if(buttonPressed == 3){ 818 y = y + 30; 819 Serial.println("y + 30"); 820 } 821 if(buttonPressed == 4){ 822 x = 0; 823 Serial.println("x = 0"); 824 } 825 if(buttonPressed == 5){ 826 x = 0; 827 y = 0; 828 z = 0; 829 Serial.println("xyz all 0"); 830 } 831 } 832 else if (y >> 0){ 833 if(buttonPressed == 1){ 834 z = z + 100; 835 Serial.println("z + 100"); 836 } 837 if(buttonPressed == 2){ 838 z = z + 200; 839 Serial.println("z + 200"); 840 } 841 if(buttonPressed == 3){ 842 if(currentScreen != 31){ 843 z = z + 300; 844 Serial.println("z + 300"); 845 } 846 } 847 if(buttonPressed == 4){ 848 if(z == 0){ 849 y = 0; 850 Serial.println("y = 0"); 851 } 852 else if(z >> 0){ 853 z = 0; 854 Serial.println("z = 0"); 855 } 856 } 857 if(buttonPressed == 5){ 858 x = 0; 859 y = 0; 860 z = 0; 861 Serial.println("xyz all 0"); 862 } 863 }//y>0 864 }//x>0 865 currentScreen = z+y+x; 866 867 868//================button group exceptions================ 869//================button group exceptions================ 870 if(currentScreen == 111){ // HEAD MOTOR CONTOL 871 buttonGroup=1; 872 } 873 if(currentScreen == 12){ // MOUTH MOTOR CONTOL 874 buttonGroup=1; 875 } 876 if(currentScreen == 13){ // HEAD MOTOR CONTOL 877 buttonGroup=2; 878 } 879 if(currentScreen == 211){ // MOUTH MOTOR CONTOL 880 buttonGroup=2; 881 } 882 if(currentScreen == 31){ // BACKLIGHTIMER 883 buttonGroup=3; 884 } 885//================button group exceptions================ 886//================button group exceptions================ 887 888} 889//-------------------------- end whatScreen function ------------------------- 890//-------------------------- end whatScreen function ------------------------- 891//-------------------------- end whatScreen function ------------------------- 892//-------------------------- end whatScreen function ------------------------- 893//-------------------------- end whatScreen function ------------------------- 894 895//**************************************************************************************************** 896//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 897//**************************************************************************************************** 898//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 899//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 900//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 901//**************************************************************************************************** 902//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 903//**************************************************************************************************** 904//-------------------------- begin callScreen function ------------------------- 905//-------------------------- begin callScreen function ------------------------- 906//-------------------------- begin callScreen function ------------------------- 907//-------------------------- begin callScreen function ------------------------- 908//-------------------------- begin callScreen function ------------------------- 909//-------------------------- begin callScreen function ------------------------- 910//-------------------------- begin callScreen function ------------------------- 911//-------------------------- begin callScreen function ------------------------- 912//-------------------------- begin callScreen function ------------------------- 913//-------------------------- begin callScreen function ------------------------- 914//-------------------------- begin callScreen function ------------------------- 915 916int callScreen(){ 917 Tft.fillRectangle(0, 0, 240, 320, BLACK); 918 919//<><><><><><><><><><><><><><><><><><><><><><><><> 920//<><><><><><><><> begin screen 0000 master <><><><><><><><> 921//<><><><><><><><><><><><><><><><><><><><><><><><> 922if(currentScreen == 0){ 923 // " " 924 Tft.drawString("GRAVES",0,5,4, GREEN); 925 Tft.drawString("INTERFACE",18,50,4,GREEN); 926 Tft.drawString("Main Controls", 05,130, 3, GREEN); 927 Tft.drawString("Mouth Control", 05, 195, 3, CYAN); 928 Tft.drawString("Head Control", 10, 260, 3, BLUE); 929} 930//<><><><><><><><><><><><><><><><><><><><><><><><> 931//<><><><><><><><> end screen 0000 master <><><><><><><><><> 932//<><><><><><><><><><><><><><><><><><><><><><><><> 933 934//<><><><><><><><><><><><><><><><><><><><><><><><> 935//<><><><><><><><> begin screen 0001 <><><><><><><><> 936//<><><><><><><><><><><><><><><><><><><><><><><><> 937 if(currentScreen == 1){ 938 // " " 939 Tft.drawString("MAIN", 65, 5, 4, GREEN); 940 Tft.drawString("CONTROLS", 25, 50, 4, GREEN); 941 Tft.drawString("Motors Power", 15, 130, 3, RED); 942 Tft.drawString("Sensors", 55, 195, 3, YELLOW); 943 Tft.drawString("Light Timeout", 5, 260, 3, WHITE); 944 Tft.drawString("<", 0, 160, 3, GREEN); // back button 945} 946//<><><><><><><><><><><><><><><><><><><><><><><><> 947//<><><><><><><><> end screen 0001 <><><><><><><><><> 948//<><><><><><><><><><><><><><><><><><><><><><><><> 949 950 951//<><><><><><><><><><><><><><><><><><><><><><><><> 952//<><><><><><><><> begin screen 0011 <><><><><><><><> 953//<><><><><><><><><><><><><><><><><><><><><><><><> 954 if(currentScreen == 11){ 955 // " " 956 Tft.drawString("MOTOR", 60, 5, 4, RED); 957 Tft.drawString("CONTROLS", 20, 50, 4, RED); 958 Tft.drawString("Head Motor", 30, 130, 3, BLUE); 959 Tft.drawString("Mouth Motor", 25, 195, 3, CYAN); 960 Tft.drawString("<", 0, 160, 3, GREEN); // back button 961} 962//<><><><><><><><><><><><><><><><><><><><><><><><> 963//<><><><><><><><> end screen 0013 <><><><><><><><><> 964//<><><><><><><><><><><><><><><><><><><><><><><><> 965 966//<><><><><><><><><><><><><><><><><><><><><><><><> 967//<><><><><><><><> begin screen 0111 <><><><><><><><> 968//<><><><><><><><><><><><><><><><><><><><><><><><> 969 if(currentScreen == 111){ 970 // " " 971 Tft.drawString("HEAD MOTOR",0,5,4,BLUE); 972 Tft.drawString("CONTROL", 40, 50, 4, BLUE); 973 Tft.drawString("On", 100, 130, 3, GREEN); 974 Tft.drawString("Off", 95, 195, 3, RED); 975 Tft.drawString("<", 0, 160, 3, GREEN); // back button 976} 977//<><><><><><><><><><><><><><><><><><><><><><><><> 978//<><><><><><><><> end screen 0111 <><><><><><><><><> 979//<><><><><><><><><><><><><><><><><><><><><><><><> 980 981//<><><><><><><><><><><><><><><><><><><><><><><><> 982//<><><><><><><><> begin screen 0211 <><><><><><><><> 983//<><><><><><><><><><><><><><><><><><><><><><><><> 984 if(currentScreen == 211){ 985 // " " 986 Tft.drawString("MOUTH", 60, 5, 4, CYAN); 987 Tft.drawString("MOTOR", 60, 50, 4, CYAN); 988 Tft.drawString("On", 100, 130, 3, GREEN); 989 Tft.drawString("Off", 95, 195, 3, RED); 990 Tft.drawString("<", 0, 160, 3, GREEN); // back button 991} 992//<><><><><><><><><><><><><><><><><><><><><><><><> 993//<><><><><><><><> end screen 0211 <><><><><><><><><> 994//<><><><><><><><><><><><><><><><><><><><><><><><> 995 996//<><><><><><><><><><><><><><><><><><><><><><><><> 997//<><><><><><><><> begin screen 0031 <><><><><><><><> 998//<><><><><><><><><><><><><><><><><><><><><><><><> 999 if(currentScreen == 31){ 1000 // " " 1001 Tft.drawString("BACKLIGHT",10,5,4,WHITE); 1002 Tft.drawString("TIME OUT",20,50,4,WHITE); 1003 Tft.drawString("2 minutes", 35,130, 3, GREEN); 1004 Tft.drawString("15 seconds", 30, 195, 3, RED); 1005 Tft.drawString("5 seconds", 35, 260, 3, WHITE); 1006 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1007} 1008 1009//<><><><><><><><><><><><><><><><><><><><><><><><> 1010//<><><><><><><><> end screen 0031 <><><><><><><><><> 1011//<><><><><><><><><><><><><><><><><><><><><><><><> 1012 1013//<><><><><><><><><><><><><><><><><><><><><><><><> 1014//<><><><><><><><> begin screen 0021 <><><><><><><><> 1015//<><><><><><><><><><><><><><><><><><><><><><><><> 1016 if(currentScreen == 21){ 1017 // " " 1018 Tft.drawString("INCOMING", 20, 5, 4, GREEN); 1019 Tft.drawString("SENSORS", 30, 50, 4,YELLOW); 1020 Tft.drawString("Head Sensors", 15, 130, 3, YELLOW); 1021 Tft.drawString("Mouth Sensors", 05, 195, 3, YELLOW); 1022 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1023} 1024//<><><><><><><><><><><><><><><><><><><><><><><><> 1025//<><><><><><><><> end screen 0021 <><><><><><><><><> 1026//<><><><><><><><><><><><><><><><><><><><><><><><> 1027 1028//<><><><><><><><><><><><><><><><><><><><><><><><> 1029//<><><><><><><><> begin screen 0121 <><><><><><><><> 1030//<><><><><><><><><><><><><><><><><><><><><><><><> 1031 if(currentScreen == 121){ 1032 // " " 1033 Tft.drawString("HEAD", 65, 5, 4, BLUE); 1034 Tft.drawString("SENSORS", 30, 50, 4, YELLOW); 1035 Tft.drawString("PIR position ", 10, 130, 3, YELLOW); 1036 Tft.drawString("detected", 05, 195, 3, YELLOW); 1037 Tft.drawChar(incomingHeadByte, 185, 195, 3, YELLOW); 1038 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1039} 1040//<><><><><><><><><><><><><><><><><><><><><><><><> 1041//<><><><><><><><> end screen 0121 <><><><><><><><><> 1042//<><><><><><><><><><><><><><><><><><><><><><><><> 1043 1044//<><><><><><><><><><><><><><><><><><><><><><><><> 1045//<><><><><><><><> begin screen 0221 <><><><><><><><> 1046//<><><><><><><><><><><><><><><><><><><><><><><><> 1047 if(currentScreen == 221){ 1048 // " " 1049 Tft.drawString("MOUTH", 55, 5, 4, CYAN); 1050 Tft.drawString("SENSORS", 30, 50, 4, YELLOW); 1051 Tft.drawString("Echo Sense", 30, 130, 3, YELLOW); 1052 Tft.drawString("Graves Sense", 10, 195, 3, YELLOW); 1053 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1054} 1055//<><><><><><><><><><><><><><><><><><><><><><><><> 1056//<><><><><><><><> end screen 0221 <><><><><><><><><> 1057//<><><><><><><><><><><><><><><><><><><><><><><><> 1058 1059 1060//<><><><><><><><><><><><><><><><><><><><><><><><> 1061//<><><><><><><><> begin screen 0002 <><><><><><><><> 1062//<><><><><><><><><><><><><><><><><><><><><><><><> 1063 if(currentScreen == 2){ 1064 // " " 1065 Tft.drawString("MOUTH", 50, 5, 4, CYAN); 1066 Tft.drawString("CONTROL", 30, 50, 4, CYAN); 1067 Tft.drawString("Motor on/off", 15, 130, 3, RED); 1068 Tft.drawString("Sensor on/off", 05, 195, 3, YELLOW); 1069 Tft.drawString("Monitor", 5, 260, 3, YELLOW); 1070 Tft.drawChar(incomingMouthByte, 185, 260, 3, YELLOW); 1071 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1072 } 1073//<><><><><><><><><><><><><><><><><><><><><><><><> 1074//<><><><><><><><> end screen 0002 <><><><><><><><><> 1075//<><><><><><><><><><><><><><><><><><><><><><><><> 1076 1077 1078//<><><><><><><><><><><><><><><><><><><><><><><><> 1079//<><><><><><><><> begin screen 0012 <><><><><><><><> 1080//<><><><><><><><><><><><><><><><><><><><><><><><> 1081 if(currentScreen == 12){ 1082 // " " 1083 Tft.drawString("MOUTH", 60, 5, 4, CYAN); 1084 Tft.drawString("MOTOR", 60, 50, 4, CYAN); 1085 Tft.drawString("On", 100, 130, 3, GREEN); 1086 Tft.drawString("Off", 95, 195, 3, RED); 1087 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1088} 1089//<><><><><><><><><><><><><><><><><><><><><><><><> 1090//<><><><><><><><> end screen 0012 <><><><><><><><><> 1091//<><><><><><><><><><><><><><><><><><><><><><><><> 1092 1093 1094//<><><><><><><><><><><><><><><><><><><><><><><><> 1095//<><><><><><><><> begin screen 0022 <><><><><><><><> 1096//<><><><><><><><><><><><><><><><><><><><><><><><> 1097 if(currentScreen == 22){ 1098 // " " 1099 Tft.drawString("SENSOR", 40, 5, 4, YELLOW); 1100 Tft.drawString("SELECT", 40, 50, 4,YELLOW); 1101 Tft.drawString("Echo Sense", 30, 130, 3, YELLOW); 1102 Tft.drawString("Graves Sense", 10, 195, 3, YELLOW); 1103 Tft.drawString("Monitor Both", 10, 260, 3, YELLOW); 1104 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1105} 1106//<><><><><><><><><><><><><><><><><><><><><><><><> 1107//<><><><><><><><> end screen 0022 <><><><><><><><><> 1108//<><><><><><><><><><><><><><><><><><><><><><><><> 1109 1110 1111 1112//<><><><><><><><><><><><><><><><><><><><><><><><> 1113//<><><><><><><><> begin screen 0122 <><><><><><><><> 1114//<><><><><><><><><><><><><><><><><><><><><><><><> 1115 if(currentScreen == 122){ 1116 // " " 1117 Tft.drawString("ECHO", 70, 5, 4, YELLOW); 1118 Tft.drawString("SENSOR", 35, 50, 4, YELLOW); 1119 Tft.drawString("On", 100, 130, 3, GREEN); 1120 Tft.drawString("Off", 95, 195, 3, RED); 1121 Tft.drawString("Monitor", 5, 260, 3, GREEN); 1122 Tft.drawChar(incomingMouthByte, 185, 260, 3, YELLOW); 1123 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1124} 1125//<><><><><><><><><><><><><><><><><><><><><><><><> 1126//<><><><><><><><> end screen 0122 <><><><><><><><><> 1127//<><><><><><><><><><><><><><><><><><><><><><><><> 1128 1129//<><><><><><><><><><><><><><><><><><><><><><><><> 1130//<><><><><><><><> begin screen 0222 <><><><><><><><> 1131//<><><><><><><><><><><><><><><><><><><><><><><><> 1132 if(currentScreen == 222){ 1133 // " " 1134 Tft.drawString("GRAVES",35,5,4,BLUE); 1135 Tft.drawString("SENSOR",35,50,4,YELLOW); 1136 Tft.drawString("On", 100, 130, 3, GREEN); 1137 Tft.drawString("Off", 95, 195, 3, RED); 1138 Tft.drawString("Monitor", 5, 260, 3, GREEN); 1139 Tft.drawChar(incomingMouthByte, 185, 260, 3, YELLOW); 1140 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1141} 1142//<><><><><><><><><><><><><><><><><><><><><><><><> 1143//<><><><><><><><> end screen 0222 <><><><><><><><><> 1144//<><><><><><><><><><><><><><><><><><><><><><><><> 1145 1146//<><><><><><><><><><><><><><><><><><><><><><><><> 1147//<><><><><><><><> begin screen 0032 <><><><><><><><> 1148//<><><><><><><><><><><><><><><><><><><><><><><><> 1149 if(currentScreen == 32){ 1150 // " " 1151 Tft.drawString("ALL", 90, 5, 4, BLUE); 1152 Tft.drawString("SENSORS", 35, 50, 4, YELLOW); 1153 Tft.drawString("Echo", 35, 130, 3, BLUE); 1154 Tft.drawChar(incomingMouthByte, 185, 130, 3, YELLOW); 1155 Tft.drawString("Graves", 30, 195, 3, GREEN); 1156 Tft.drawChar(incomingMouthByte, 185, 130, 3, YELLOW); 1157 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1158} 1159//<><><><><><><><><><><><><><><><><><><><><><><><> 1160//<><><><><><><><> end screen 0032 <><><><><><><><><> 1161//<><><><><><><><><><><><><><><><><><><><><><><><> 1162 1163//<><><><><><><><><><><><><><><><><><><><><><><><> 1164//<><><><><><><><> begin screen 0003 <><><><><><><><> 1165//<><><><><><><><><><><><><><><><><><><><><><><><> 1166 if(currentScreen == 3){ 1167 // " " 1168 Tft.drawString("HEAD", 70, 5, 4, BLUE); 1169 Tft.drawString("CONTROL", 30, 50, 4, RED); 1170 Tft.drawString("Motor On/Off", 15, 130, 3, RED); 1171 Tft.drawString("Manual Point", 15, 195, 3, RED); 1172 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1173} 1174//<><><><><><><><><><><><><><><><><><><><><><><><> 1175//<><><><><><><><> end screen 0003 <><><><><><><><><> 1176//<><><><><><><><><><><><><><><><><><><><><><><><> 1177 1178//<><><><><><><><><><><><><><><><><><><><><><><><> 1179//<><><><><><><><> begin screen 0013 <><><><><><><><> 1180//<><><><><><><><><><><><><><><><><><><><><><><><> 1181 if(currentScreen == 13){ 1182 // " " 1183 Tft.drawString("HEAD", 70, 5, 4, BLUE); 1184 Tft.drawString("MOTOR", 60, 50, 4, RED); 1185 Tft.drawString("On", 100, 130, 3, GREEN); 1186 Tft.drawString("Off", 95, 195, 3, RED); 1187 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1188} 1189//<><><><><><><><><><><><><><><><><><><><><><><><> 1190//<><><><><><><><> end screen 0013 <><><><><><><><><> 1191//<><><><><><><><><><><><><><><><><><><><><><><><> 1192 1193//<><><><><><><><><><><><><><><><><><><><><><><><> 1194//<><><><><><><><> begin screen 0023 <><><><><><><><> 1195//<><><><><><><><><><><><><><><><><><><><><><><><> 1196 if(currentScreen == 23){ 1197 // " " 1198 Tft.drawString("HEAD", 70, 5, 4, BLUE); 1199 Tft.drawString("POINTER", 35, 50, 4, RED); 1200 Tft.drawString("Left", 85, 130, 3, RED); 1201 Tft.drawString("Right", 75, 195, 3, RED); 1202 Tft.drawString("Center", 65, 260, 3, RED); 1203 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1204} 1205//<><><><><><><><><><><><><><><><><><><><><><><><> 1206//<><><><><><><><> end screen 0023 <><><><><><><><><> 1207//<><><><><><><><><><><><><><><><><><><><><><><><> 1208 1209 1210//<><><><><><><><><><><><><><><><><><><><><><><><> 1211//<><><><><><><><> begin screen 0422 <><><><><><><><> 1212//<><><><><><><><><><><><><><><><><><><><><><><><> 1213 if(currentScreen == 422){ 1214 // " " 1215 Tft.drawString("Command Sent",0,5,3,BLUE); 1216 Tft.drawString("Press Back to",0,55,3,YELLOW); 1217 Tft.drawString("Contiue", 50,105, 3, BLUE); 1218 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1219} 1220//<><><><><><><><><><><><><><><><><><><><><><><><> 1221//<><><><><><><><> end screen 0422 <><><><><><><><><> 1222//<><><><><><><><><><><><><><><><><><><><><><><><> 1223 1224 1225////<><><><><><><><><><><><><><><><><><><><><><><><> 1226////<><><><><><><><> begin screen lost <><><><><><><><> 1227////<><><><><><><><><><><><><><><><><><><><><><><><> 1228// else if(currentScreen){ 1229// // " " 1230// Tft.drawString("Screen not",0,5,3,BLUE); 1231// Tft.drawString("found. Please",40,50,3,YELLOW); 1232// Tft.drawString("use the back", 80,130, 3, BLUE); 1233// Tft.drawString("button to", 05, 195, 3, GREEN); 1234// Tft.drawString("return to fun", 10, 260, 3, GREEN); 1235// Tft.drawString("<", 0, 160, 3, GREEN); // back button 1236//} 1237////<><><><><><><><><><><><><><><><><><><><><><><><> 1238////<><><><><><><><> end screen lost <><><><><><><><><> 1239////<><><><><><><><><><><><><><><><><><><><><><><><> 1240 1241 1242}// callScreen 1243//-------------------------- end callScreen function ------------------------- 1244//-------------------------- end callScreen function ------------------------- 1245//-------------------------- end callScreen function ------------------------- 1246//-------------------------- end callScreen function ------------------------- 1247//-------------------------- end callScreen function ------------------------- 1248//-------------------------- end callScreen function ------------------------- 1249//-------------------------- end callScreen function ------------------------- 1250//-------------------------- end callScreen function ------------------------- 1251//-------------------------- end callScreen function ------------------------- 1252//-------------------------- end callScreen function ------------------------- 1253//-------------------------- end callScreen function ------------------------- 1254//-------------------------- end callScreen function ------------------------- 1255//-------------------------- end callScreen function ------------------------- 1256 1257 1258//**************************************************************************************************** 1259//**************************************************************************************************** 1260 1261 1262 1263 1264 1265 1266 1267//**************************************************************************************************** 1268//**************************************************************************************************** 1269 1270// fin
13102018 - Bodmer to the rescue!
c_cpp
Big shout out to Bodmer for helping identify my spotty understanding of data types. I had wrongly used int to store a millis() value and the prog would crash after a minute or two. changed them to unsigned longs and it chooches along flawlessly now! I was going to rewrite menus, but now I think I'll wait to establish communication from the mega to the dos uno's. I'll figure out what data I can pass back and forth before the menu rewrite. Thanks again, Bodmer!
1/* 2last edit sun oct 13 2018 3coded from scratch by wylie jones 4wyliejones@gmail.com 5 6Graves multi arduino build 10/2018 7Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 8two arduino uno's 9slave1 arduino uno to sense sound from graves and echo dot to control mouth 10slave2 arduino uno to control passive sensor array and head servo 11 12sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 13 14 analogue pin speaker + 15 \ / (red from speaker) 16 \ / 17 \ / 18 *--------[=]-----------*---------[=]----------* 19 | resistor \ resistor | 20 | \ | 21 |(red with white) \ |to arduino ground (black with white) 22to arduino 5v+ speaker - 23 (black from speaker) 24 25*/ 26//end notes 27//end notes 28//end notes 29//end notes 30//end notes 31//end notes 32 33 34//********************************************************* 35//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 36//********************************************************* 37 38 39//begin declarations 40//begin declarations 41//begin declarations 42//begin declarations 43//begin declarations 44//begin declarations 45//begin declarations 46 47//#include <TFT.h> 48//#include <Servo.h> 49//#include <stdint.h> 50//#include <SD.h> 51#include <TFTv2.h> 52#include <SPI.h> 53#include <SeeedTouchScreen.h> 54 55//const int PIN_SD_CS = 4; // pin of sd card 56 57TouchScreen ts = TouchScreen(XP, YP, XM, YM); 58int buttonPressed; // stores which button was pressed 59unsigned long newButtonTime; // debounce 60unsigned long oldButtonTime; // debounce 61unsigned long buttonTimeDifference; // debounce 62unsigned long debounceTime; // debounce 63int currentScreen; // identifies current screen by adding x y and z 64int x; // for ones 65int y; // for tens 66int z; // for hundreds 67 68int zMax; // maximum pressure to detect 69int zMin; // minimum pressure to detect 70unsigned long backlightTimer; // for backlight timeout 71int backLightState; // status of backlight 1 for on and 0 for off 72unsigned long backlightTimeDifference; 73unsigned long newBacklightTime; 74unsigned long oldBacklightTime; 75 76//end declarations 77//end declarations 78//end declarations 79//end declarations 80//end declarations 81//end declarations 82//end declarations 83//end declarations 84//end declarations 85 86//********************************************************* 87//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 88//********************************************************* 89 90// begin void setup 91// begin void setup 92// begin void setup 93// begin void setup 94// begin void setup 95// begin void setup 96// begin void setup 97// begin void setup 98// begin void setup 99// begin void setup 100// begin void setup 101void setup() { 102Serial.begin(115200); 103 oldButtonTime = millis(); 104 newButtonTime = millis(); 105 Tft.TFTinit(); // init TFT library 106 TFT_BL_ON; // turn on the background light 107 backLightState = 1; 108 x = 0; 109 y = 0; 110 z = 0; 111 buttonPressed = 4; 112 113 //////////////////////////////// 114 //// manually set variables //// 115 //////////////////////////////// 116 117 debounceTime = 1000; // button debounce in milliseconds 118 zMax = 460; // maximum pressure to detect 119 zMin = 100; // minimum pressure to detect 120 backlightTimer = 5000; // for backlight timeout 121 122 123 currentScreen = 0; 124 callScreen(); 125 126} //void setup() 127// end void setup 128// end void setup 129// end void setup 130// end void setup 131// end void setup 132// end void setup 133// end void setup 134// end void setup 135 136//********************************************************* 137//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 138//********************************************************* 139 140// begin void loop 141// begin void loop 142// begin void loop 143// begin void loop 144// begin void loop 145// begin void loop 146// begin void loop 147// begin void loop 148// begin void loop 149// begin void loop 150// begin void loop 151// begin void loop 152// begin void loop 153// begin void loop 154 155void loop() { 156 tftBacklightTimeout(); // check time and turn off backlight 157 tftDetect(); // gather information from touch screen touches 158 buttonTimeDifference = newButtonTime - oldButtonTime; 159 if(debounceTime < buttonTimeDifference){ 160 whatScreen(); 161 callScreen(); 162 oldButtonTime = newButtonTime; 163 showStuff(); // serial prints 164 tftDisplay(); // display x y coordinates on tft display 165 } 166} //void loop() 167 168// end of void loop 169// end of void loop 170// end of void loop 171// end of void loop 172// end of void loop 173// end of void loop 174// end of void loop 175// end of void loop 176// end of void loop 177// end of void loop 178// end of void loop 179// end of void loop 180// end of void loop 181// end of void loop 182// end of void loop 183 184//**************************************************************************************************** 185//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 186//**************************************************************************************************** 187///////////////////////////////////////////////////////////////////////////////////////////////////////// 188///////////////////////////////////////// functions /////////////////////////////////////////////////// 189///////////////////////////////////////////////////////////////////////////////////////////////////////// 190//**************************************************************************************************** 191//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 192//**************************************************************************************************** 193 194//--------------------------begin tftBacklightTimeout---------------------------------- 195void tftBacklightTimeout(){ 196 newBacklightTime = millis(); 197 if(backLightState = 0){ 198 backlightTimeDifference = newBacklightTime - oldBacklightTime; 199 if(backlightTimer > backlightTimeDifference){ 200 backlightTimeDifference = newBacklightTime - oldBacklightTime; 201 TFT_BL_ON; // turn on the background light 202 backLightState = 1; 203 oldBacklightTime = millis(); 204 } 205 } 206 if(backLightState = 1){ 207 backlightTimeDifference = newBacklightTime - oldBacklightTime; 208 if(backlightTimer < backlightTimeDifference){ 209 backlightTimeDifference = newBacklightTime - oldBacklightTime; 210 TFT_BL_OFF; // turn off the background light 211 backLightState = 0; 212 oldBacklightTime = millis(); 213 } 214 } 215} 216//--------------------------end tftBacklightTimeout---------------------------------- 217 218//**************************************************************************************************** 219//**************************************************************************************************** 220 221//--------------------------begin tftDetect---------------------------------- 222//--------------------------begin tftDetect---------------------------------- 223//--------------------------begin tftDetect---------------------------------- 224//--------------------------begin tftDetect---------------------------------- 225int tftDetect(){ 226 Point p = ts.getPoint(); 227 if(zMin<p.z && p.z<zMax){ 228 TFT_BL_ON; // turn on the background light 229 backLightState = 1; 230 oldBacklightTime = millis(); 231 newButtonTime = millis(); 232 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 233 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 234//Button 1 235 if(75<p.x && p.x<140){ 236 if(100<p.y && p.y<164){ 237 buttonPressed = 1; 238 } 239//Button 2 240 if(164<p.y && p.y<240){ 241 buttonPressed = 2; 242 } 243//Button 3 244 if(240<p.y && p.y<310){ 245 buttonPressed = 3; 246 } 247 } 248 } 249//Button 4 250 if(10<p.x && p.x<75){ 251 if(100<p.y && p.y<240){ 252 buttonPressed = 4; 253 } 254 } 255//Button 5 256 if(250<p.x && p.x<275){ 257 if(0<p.y && p.y<75){ 258 buttonPressed = 5; 259 } 260 } 261}//void tftDetect 262//--------------------------end tftDetect code---------------------------------- 263//--------------------------end tftDetect code---------------------------------- 264//--------------------------end tftDetect code---------------------------------- 265//--------------------------end tftDetect code---------------------------------- 266//--------------------------end tftDetect code---------------------------------- 267//**************************************************************************************************** 268//**************************************************************************************************** 269//-------------------------- begin whatScreen function ------------------------- 270//-------------------------- begin whatScreen function ------------------------- 271//-------------------------- begin whatScreen function ------------------------- 272//-------------------------- begin whatScreen function ------------------------- 273 274int whatScreen(){ 275 if(x == 0){ 276 if(buttonPressed == 1){ 277 x = x + 1; 278 Serial.println("x + 1"); 279 } 280 if(buttonPressed == 2){ 281 x = x + 2; 282 Serial.println("x + 2"); 283 } 284 if(buttonPressed == 3){ 285 x = x + 3; 286 Serial.println("x + 3"); 287 } 288 if(buttonPressed == 4){ 289 x = 0; 290 Serial.println("x = 0"); 291 } 292 if(buttonPressed == 5){ 293 x = 0; 294 y = 0; 295 z = 0; 296 Serial.println("xyz all 0"); 297 } 298 } 299 else if(x >> 0){ 300 if(y == 0){ 301 if(buttonPressed == 1){ 302 y = y + 10; 303 Serial.println("y + 10"); 304 } 305 if(buttonPressed == 2){ 306 y = y + 20; 307 Serial.println("y + 20"); 308 } 309 if(buttonPressed == 3){ 310 y = y + 30; 311 Serial.println("y + 30"); 312 } 313 if(buttonPressed == 4){ 314 x = 0; 315 Serial.println("x = 0"); 316 } 317 if(buttonPressed == 5){ 318 x = 0; 319 y = 0; 320 z = 0; 321 Serial.println("xyz all 0"); 322 } 323 } 324 else if (y >> 0){ 325 if(buttonPressed == 1){ 326 z = z + 100; 327 Serial.println("z + 100"); 328 } 329 if(buttonPressed == 2){ 330 z = z + 200; 331 Serial.println("z + 200"); 332 } 333 if(buttonPressed == 3){ 334 z = z + 300; 335 Serial.println("z + 300"); 336 } 337 if(buttonPressed == 4){ 338 if(z == 0){ 339 y = 0; 340 Serial.println("y = 0"); 341 } 342 else if(z >> 0){ 343 z = 0; 344 Serial.println("z = 0"); 345 } 346 } 347 if(buttonPressed == 5){ 348 x = 0; 349 y = 0; 350 z = 0; 351 Serial.println("xyz all 0"); 352 } 353 }//y>0 354 }//x>0 355 currentScreen = z+y+x; 356} 357//-------------------------- end whatScreen function ------------------------- 358//-------------------------- end whatScreen function ------------------------- 359//-------------------------- end whatScreen function ------------------------- 360//-------------------------- end whatScreen function ------------------------- 361//-------------------------- end whatScreen function ------------------------- 362 363//**************************************************************************************************** 364//**************************************************************************************************** 365 366//--------------------------begin arduino master data fetch calls---------------------------------- 367// call slave1 arduino for data 368// call slave2 arduino for data 369//--------------------------end arduino master data fetch calls------------------------------------ 370 371//**************************************************************************************************** 372//**************************************************************************************************** 373 374//--------------------------begin tftDisplay code---------------------------------- 375void tftDisplay(){ 376 Point p = ts.getPoint(); 377 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 378 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 379 Tft.fillRectangle(0, 160, 60, 30, BLACK); 380 Tft.drawNumber((p.x), 0, 160, 3, GREEN); 381 Tft.fillRectangle(180, 160, 60, 30, BLACK); 382 Tft.drawNumber((p.y), 180, 160, 3, GREEN); 383 Tft.fillRectangle(80, 160, 60, 30, BLACK); 384 Tft.drawNumber((buttonPressed), 80, 160, 3, GREEN); 385}// void tftDisplay 386//--------------------------end tftDisplay code------------------------------------ 387 388//**************************************************************************************************** 389//**************************************************************************************************** 390 391//-------------------------- begin slave1 data fetch function -------------------------- 392//-------------------------- end slave1 data fetch function -------------------------- 393 394//**************************************************************************************************** 395//**************************************************************************************************** 396 397//-------------------------- begin slave2 data fetch function -------------------------- 398//-------------------------- end slave2 data fetch function ------------------------- 399 400//**************************************************************************************************** 401//**************************************************************************************************** 402 403//-------------------------- begin serial display function -------------------------- 404void showStuff(){ 405 Serial.println("------/ last update /-------"); 406// Serial.println("------begin display-------"); 407 Serial.print("buttonPressed "); 408 Serial.println(buttonPressed); 409 Serial.print("x "); 410 Serial.println(x); 411 Serial.print("y "); 412 Serial.println(y); 413 Serial.print("z "); 414 Serial.println(z); 415 Serial.print("currentScreen "); 416 Serial.println(currentScreen); 417// Serial.println("-------end display--------"); 418 Serial.println(""); 419 Serial.println(""); 420 Serial.println(""); 421 } 422//-------------------------- end serial display function ------------------------- 423 424 425//**************************************************************************************************** 426//**************************************************************************************************** 427 428//--------------------------- Primary screen maps -------------------------------- 429/* 430******** 431updates needed 432******** 4331 ditch the contrast 4342 ditch the brightness 4353 setup screen timeout 436 437 438 439 440screen 0000 A)Home 441 screen 0001 a)settings 442 screen 0011 -brightness 443 screen 0011 -contrast 444 screen 0011 -screen lock time out 445 screen 0001 b)sensor monitors 446 screen 0021 -pir 447 screen 0121 *report pir detection 448 screen 0021 -sound 449 screen 0221 *sense alexa sound 450 screen 0221 *sense graves sound 451 screen 0221 *report mouth servo position 452 screen 0221 *adjust sensitivity? 453 screen 0021 -head potentiometer 454 screen 0021 -bluetooth 455 screen 0001 c)bluetooth 456 screen 0031 -on 457 screen 0031 -off 458 screen 0031 -monitor 459screen 0000 B)Mouth Control 460 screen 0002 a)test button 461 screen 0012 -open 462 screen 0012 -close 463 screen 0012 -push button chicken switch 464 screen 0002 b)sound sensors on/off 465 screen 0022 -alexa sense 466 screen 0122 *on 467 screen 0122 *off 468 screen 0122 *monitor sensor 469 screen 0022 -graves sense 470 screen 0222 *on 471 screen 0222 *off 472 screen 0222 *monitor sensors 473 screen 0002 c)sound sensor status 474 screen 0032 -alexa 475 screen 0032 -graves 476screen 0000 C)Head Control 477 screen 0003 a)pir on/off 478 screen 0013 -on 479 screen 0013 -off 480 screen 0013 -sensor 481 screen 0003 b)manual point 482 screen 0023 -slider 483*/ 484//**************************************************************************************************** 485//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 486//**************************************************************************************************** 487//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 488//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 489//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 490//**************************************************************************************************** 491//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 492//**************************************************************************************************** 493 494//-------------------------- begin callScreen function ------------------------- 495//-------------------------- begin callScreen function ------------------------- 496//-------------------------- begin callScreen function ------------------------- 497//-------------------------- begin callScreen function ------------------------- 498//-------------------------- begin callScreen function ------------------------- 499//-------------------------- begin callScreen function ------------------------- 500//-------------------------- begin callScreen function ------------------------- 501//-------------------------- begin callScreen function ------------------------- 502//-------------------------- begin callScreen function ------------------------- 503//-------------------------- begin callScreen function ------------------------- 504//-------------------------- begin callScreen function ------------------------- 505 506int callScreen(){ 507 Tft.fillRectangle(0, 0, 240, 320, BLACK); 508 509//<><><><><><><><><><><><><><><><><><><><><><><><> 510//<><><><><><><><> begin screen 0000 master <><><><><><><><> 511//<><><><><><><><><><><><><><><><><><><><><><><><> 512if(currentScreen == 0){ 513 // " " 514 Tft.drawString("GRAVES",0,5,4, GREEN); 515 Tft.drawString("INTERFACE",10,50,4,GREEN); 516 Tft.drawString("Home", 80,130, 3, GREEN); 517 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 518 Tft.drawString("Head Control", 10, 260, 3, GREEN); 519} 520//<><><><><><><><><><><><><><><><><><><><><><><><> 521//<><><><><><><><> end screen 0000 master <><><><><><><><><> 522//<><><><><><><><><><><><><><><><><><><><><><><><> 523 524//<><><><><><><><><><><><><><><><><><><><><><><><> 525//<><><><><><><><> begin screen 0001 <><><><><><><><> 526//<><><><><><><><><><><><><><><><><><><><><><><><> 527 if(currentScreen == 1){ 528 // " " 529 Tft.drawString("MEGA 2560",00,5,4,BLUE); 530 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 531 Tft.drawString("Settings", 10,130, 3, BLUE); 532 Tft.drawString("Sensors", 20, 195, 3, BLUE); 533 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 534 Tft.drawString("<", 0, 160, 3, GREEN); // back button 535} 536//<><><><><><><><><><><><><><><><><><><><><><><><> 537//<><><><><><><><> end screen 0001 <><><><><><><><><> 538//<><><><><><><><><><><><><><><><><><><><><><><><> 539 540//<><><><><><><><><><><><><><><><><><><><><><><><> 541//<><><><><><><><> begin screen 0011 <><><><><><><><> 542//<><><><><><><><><><><><><><><><><><><><><><><><> 543 if(currentScreen == 11){ 544 // " " 545 Tft.drawString("MEGA 2560",00,5,4,BLUE); 546 Tft.drawString("SETTINGS",10,50,4,YELLOW); 547 Tft.drawString("Brightness", 80,130, 3, BLUE); 548 Tft.drawString("Contrast", 05, 195, 3, GREEN); 549 Tft.drawString("Timeout", 10, 260, 3, GREEN); 550 Tft.drawString("<", 0, 160, 3, GREEN); // back button 551} 552 553//<><><><><><><><><><><><><><><><><><><><><><><><> 554//<><><><><><><><> end screen 0011 <><><><><><><><><> 555//<><><><><><><><><><><><><><><><><><><><><><><><> 556 557//<><><><><><><><><><><><><><><><><><><><><><><><> 558//<><><><><><><><> begin screen 0021 <><><><><><><><> 559//<><><><><><><><><><><><><><><><><><><><><><><><> 560 if(currentScreen == 21){ 561 // " " 562 Tft.drawString("MEGA 2560",00,5,4,BLUE); 563 Tft.drawString("SENSORS",10,50,4,YELLOW); 564 Tft.drawString("PIR Array", 80,130, 3, BLUE); 565 Tft.drawString("Sound", 05, 195, 3, GREEN); 566 Tft.drawString("Head Position", 10, 260, 3, GREEN); 567 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 568 Tft.drawString("<", 0, 160, 3, GREEN); // back button 569} 570//<><><><><><><><><><><><><><><><><><><><><><><><> 571//<><><><><><><><> end screen 0021 <><><><><><><><><> 572//<><><><><><><><><><><><><><><><><><><><><><><><> 573 574//<><><><><><><><><><><><><><><><><><><><><><><><> 575//<><><><><><><><> begin screen 0121 <><><><><><><><> 576//<><><><><><><><><><><><><><><><><><><><><><><><> 577 if(currentScreen == 121){ 578 // " " 579 Tft.drawString("PIR",0,5,4,BLUE); 580 Tft.drawString("ARRAY",10,50,4,YELLOW); 581 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 582 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 583 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 584 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 585 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 586 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 587 Tft.drawString("<", 0, 160, 3, GREEN); // back button 588} 589//<><><><><><><><><><><><><><><><><><><><><><><><> 590//<><><><><><><><> end screen 0121 <><><><><><><><><> 591//<><><><><><><><><><><><><><><><><><><><><><><><> 592 593//<><><><><><><><><><><><><><><><><><><><><><><><> 594//<><><><><><><><> begin screen 0221 <><><><><><><><> 595//<><><><><><><><><><><><><><><><><><><><><><><><> 596 if(currentScreen == 221){ 597 // " " 598 Tft.drawString("SOUND",0,5,4,BLUE); 599 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 600 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 601 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 602 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 603 Tft.drawString("<", 0, 160, 3, GREEN); // back button 604} 605//<><><><><><><><><><><><><><><><><><><><><><><><> 606//<><><><><><><><> end screen 0221 <><><><><><><><><> 607//<><><><><><><><><><><><><><><><><><><><><><><><> 608 609//<><><><><><><><><><><><><><><><><><><><><><><><> 610//<><><><><><><><> begin screen 0031 <><><><><><><><> 611//<><><><><><><><><><><><><><><><><><><><><><><><> 612 if(currentScreen == 31){ 613 // " " 614 Tft.drawString("Bluetooth",0,5,4,BLUE); 615 Tft.drawString("Control",10,50,4,YELLOW); 616 Tft.drawString("On", 80,130, 3, BLUE); 617 Tft.drawString("Off", 05, 195, 3, GREEN); 618 Tft.drawString("Monitor", 10, 260, 3, GREEN); 619 Tft.drawString("<", 0, 160, 3, GREEN); // back button 620} 621//<><><><><><><><><><><><><><><><><><><><><><><><> 622//<><><><><><><><> end screen 0031 <><><><><><><><><> 623//<><><><><><><><><><><><><><><><><><><><><><><><> 624 625//<><><><><><><><><><><><><><><><><><><><><><><><> 626//<><><><><><><><> begin screen 0002 <><><><><><><><> 627//<><><><><><><><><><><><><><><><><><><><><><><><> 628 if(currentScreen == 2){ 629 // " " 630 Tft.drawString("Mouth",0,5,4,BLUE); 631 Tft.drawString("Control",10,50,4,YELLOW); 632 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 633 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 634 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 635 Tft.drawString("<", 0, 160, 3, GREEN); // back button 636} 637//<><><><><><><><><><><><><><><><><><><><><><><><> 638//<><><><><><><><> end screen 0002 <><><><><><><><><> 639//<><><><><><><><><><><><><><><><><><><><><><><><> 640 641 642//<><><><><><><><><><><><><><><><><><><><><><><><> 643//<><><><><><><><> begin screen 0012 <><><><><><><><> 644//<><><><><><><><><><><><><><><><><><><><><><><><> 645 if(currentScreen == 12){ 646 // " " 647 Tft.drawString("Jaw Test",0,5,4,BLUE); 648 Tft.drawString("Operations",10,50,4,YELLOW); 649 Tft.drawString("Open", 80,130, 3, BLUE); 650 Tft.drawString("Close", 05, 195, 3, GREEN); 651 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 652 Tft.drawString("<", 0, 160, 3, GREEN); // back button 653} 654//<><><><><><><><><><><><><><><><><><><><><><><><> 655//<><><><><><><><> end screen 0012 <><><><><><><><><> 656//<><><><><><><><><><><><><><><><><><><><><><><><> 657 658 659//<><><><><><><><><><><><><><><><><><><><><><><><> 660//<><><><><><><><> begin screen 0022 <><><><><><><><> 661//<><><><><><><><><><><><><><><><><><><><><><><><> 662 if(currentScreen == 22){ 663 // " " 664 Tft.drawString("Sound",0,5,4,BLUE); 665 Tft.drawString("Sensors",10,50,4,YELLOW); 666 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 667 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 668 Tft.drawString("Monitor", 10, 260, 3, GREEN); 669 Tft.drawString("<", 0, 160, 3, GREEN); // back button 670} 671//<><><><><><><><><><><><><><><><><><><><><><><><> 672//<><><><><><><><> end screen 0022 <><><><><><><><><> 673//<><><><><><><><><><><><><><><><><><><><><><><><> 674 675 676 677//<><><><><><><><><><><><><><><><><><><><><><><><> 678//<><><><><><><><> begin screen 0122 <><><><><><><><> 679//<><><><><><><><><><><><><><><><><><><><><><><><> 680 if(currentScreen == 122){ 681 // " " 682 Tft.drawString("Alexa Sense",0,5,4,BLUE); 683 Tft.drawString("Operations",10,50,4,YELLOW); 684 Tft.drawString("On", 80,130, 3, BLUE); 685 Tft.drawString("Off", 05, 195, 3, GREEN); 686 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 687 Tft.drawString("<", 0, 160, 3, GREEN); // back button 688} 689//<><><><><><><><><><><><><><><><><><><><><><><><> 690//<><><><><><><><> end screen 0122 <><><><><><><><><> 691//<><><><><><><><><><><><><><><><><><><><><><><><> 692 693//<><><><><><><><><><><><><><><><><><><><><><><><> 694//<><><><><><><><> begin screen 0222 <><><><><><><><> 695//<><><><><><><><><><><><><><><><><><><><><><><><> 696 if(currentScreen == 222){ 697 // " " 698 Tft.drawString("Graves Sense",0,5,4,BLUE); 699 Tft.drawString("Operations",10,50,4,YELLOW); 700 Tft.drawString("On", 80,130, 3, BLUE); 701 Tft.drawString("Off", 05, 195, 3, GREEN); 702 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 703 Tft.drawString("<", 0, 160, 3, GREEN); // back button 704} 705//<><><><><><><><><><><><><><><><><><><><><><><><> 706//<><><><><><><><> end screen 0222 <><><><><><><><><> 707//<><><><><><><><><><><><><><><><><><><><><><><><> 708 709//<><><><><><><><><><><><><><><><><><><><><><><><> 710//<><><><><><><><> begin screen 0032 <><><><><><><><> 711//<><><><><><><><><><><><><><><><><><><><><><><><> 712 if(currentScreen == 32){ 713 // " " 714 Tft.drawString("Sound Sense",0,5,4,BLUE); 715 Tft.drawString("Monitors",10,50,4,YELLOW); 716 Tft.drawString("Alexa", 80,130, 3, BLUE); 717 Tft.drawString("Graves", 05, 195, 3, GREEN); 718 Tft.drawString("<", 0, 160, 3, GREEN); // back button 719} 720//<><><><><><><><><><><><><><><><><><><><><><><><> 721//<><><><><><><><> end screen 0032 <><><><><><><><><> 722//<><><><><><><><><><><><><><><><><><><><><><><><> 723 724//<><><><><><><><><><><><><><><><><><><><><><><><> 725//<><><><><><><><> begin screen 0003 <><><><><><><><> 726//<><><><><><><><><><><><><><><><><><><><><><><><> 727 if(currentScreen == 3){ 728 // " " 729 Tft.drawString("Head Control",0,5,4,BLUE); 730 Tft.drawString("Operations",10,50,4,YELLOW); 731 Tft.drawString("PIR Array", 80,130, 3, BLUE); 732 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 733 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 734 Tft.drawString("<", 0, 160, 3, GREEN); // back button 735} 736//<><><><><><><><><><><><><><><><><><><><><><><><> 737//<><><><><><><><> end screen 0003 <><><><><><><><><> 738//<><><><><><><><><><><><><><><><><><><><><><><><> 739 740//<><><><><><><><><><><><><><><><><><><><><><><><> 741//<><><><><><><><> begin screen 0013 <><><><><><><><> 742//<><><><><><><><><><><><><><><><><><><><><><><><> 743 if(currentScreen == 13){ 744 // " " 745 Tft.drawString("PIR Control",0,5,4,BLUE); 746 Tft.drawString("Operations",10,50,4,YELLOW); 747 Tft.drawString("On", 80,130, 3, BLUE); 748 Tft.drawString("Off", 05, 195, 3, GREEN); 749 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 750 Tft.drawString("<", 0, 160, 3, GREEN); // back button 751} 752//<><><><><><><><><><><><><><><><><><><><><><><><> 753//<><><><><><><><> end screen 0013 <><><><><><><><><> 754//<><><><><><><><><><><><><><><><><><><><><><><><> 755 756//<><><><><><><><><><><><><><><><><><><><><><><><> 757//<><><><><><><><> begin screen 0023 <><><><><><><><> 758//<><><><><><><><><><><><><><><><><><><><><><><><> 759 if(currentScreen == 23){ 760 // " " 761 Tft.drawString("Head Control",0,5,4,BLUE); 762 Tft.drawString("Manual Point",10,50,4,YELLOW); 763 Tft.drawString("Slider", 80,130, 3, BLUE); 764 Tft.drawString("<", 0, 160, 3, GREEN); // back button 765} 766//<><><><><><><><><><><><><><><><><><><><><><><><> 767//<><><><><><><><> end screen 0023 <><><><><><><><><> 768//<><><><><><><><><><><><><><><><><><><><><><><><> 769 770 771////<><><><><><><><><><><><><><><><><><><><><><><><> 772////<><><><><><><><> begin screen lost <><><><><><><><> 773////<><><><><><><><><><><><><><><><><><><><><><><><> 774// else if(currentScreen){ 775// // " " 776// Tft.drawString("Screen not",0,5,3,BLUE); 777// Tft.drawString("found. Please",40,50,3,YELLOW); 778// Tft.drawString("use the back", 80,130, 3, BLUE); 779// Tft.drawString("button to", 05, 195, 3, GREEN); 780// Tft.drawString("return to fun", 10, 260, 3, GREEN); 781// Tft.drawString("<", 0, 160, 3, GREEN); // back button 782//} 783////<><><><><><><><><><><><><><><><><><><><><><><><> 784////<><><><><><><><> end screen lost <><><><><><><><><> 785////<><><><><><><><><><><><><><><><><><><><><><><><> 786 787}// callScreen 788//-------------------------- end callScreen function ------------------------- 789//-------------------------- end callScreen function ------------------------- 790//-------------------------- end callScreen function ------------------------- 791//-------------------------- end callScreen function ------------------------- 792//-------------------------- end callScreen function ------------------------- 793//-------------------------- end callScreen function ------------------------- 794//-------------------------- end callScreen function ------------------------- 795//-------------------------- end callScreen function ------------------------- 796//-------------------------- end callScreen function ------------------------- 797//-------------------------- end callScreen function ------------------------- 798//-------------------------- end callScreen function ------------------------- 799//-------------------------- end callScreen function ------------------------- 800//-------------------------- end callScreen function ------------------------- 801 802 803//**************************************************************************************************** 804//**************************************************************************************************** 805 806 807 808 809 810 811 812//**************************************************************************************************** 813//**************************************************************************************************** 814 815// fin
19102018 they are playing well together
c_cpp
I updated dc bias circuit schematic. The uno mouth code is more or less done for now. It receives commands and echos back. It gives led fast or slow flash without using delay commands to signify if uno is executing functions or waiting for an on command. The single sound input will be relatively easy to duplicate for a second input for mouth movements. The second dc bias circuit is also ready along with a line tap wire made from a headphone/aux cord. The serial functions in this sketch are the same as the head sketch.
1/* 2last edit Friday oct 19 2018 3 4gravesunomouth 5 6graves project 7arduino Uno 8Slave 1 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17 18sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 19 20 analogue pin speaker + 21 \(yellow signal / (red from speaker) 22 \ wire) / 23 \ / 24 *--------[=]-----------*---------[=]----------* 25 | resistor \ resistor | 26 | \ | 27 |(red with white) \ |to arduino ground (black with white) 28to arduino 5v+ speaker - 29 (black from speaker) 30 31*/ 32#include <Servo.h> 33#include <SPI.h> 34 35//---------------------begin declarations----------------------- 36// for servo actions 37Servo mouthServo; 38 39// for gathering and mapping sound data 40int soundPin=A5; // incoming lead from dc bias circuit 41int soundDetected; // stores value from sound pin 42int soundLevel; // converted values that only include 512-1024 43int soundMap; // conversion from 512-1024 to 0-255 44int servoMap; // conversion from 0-255 to 100-70 45 46// communication 47char incomingMouthByte; // for incoming serial data 48char outgoingMouthByte; // for a bit more talkative serial data 49int mouthOnOffNew; // stores mouth state from serial connection 50int mouthOnOffOld; // stores mouth state from serial connection 51int mouthOnOffAdjusted; // value adjusted by 48 for ascii 52 53// for blinking 54const int ledPin = LED_BUILTIN;// the number of the LED pin 55int ledState = LOW; // ledState used to set the LED 56unsigned long previousMillis = 0; // will store last time LED was updated 57//---------------------end declarations----------------------- 58//********************************************************* 59//********************************************************* 60//---------------------begin void setup----------------------- 61//---------------------begin void setup----------------------- 62//---------------------begin void setup----------------------- 63void setup(){ 64 delay(5000); 65 Serial.begin(9600); 66 mouthServo.attach(6); 67 incomingMouthByte = 0; // for incoming serial data 68 outgoingMouthByte = 0; // for a little more talkative serial data 69 mouthOnOffNew = 1; // stores mouth state from serial connection 70 mouthOnOffOld = 1; // stores mouth state from serial connection 71 pinMode(ledPin, OUTPUT); 72} 73//---------------------end void setup----------------------- 74//---------------------end void setup----------------------- 75//---------------------end void setup----------------------- 76//********************************************************** 77//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 78//********************************************************** 79//---------------------begin void loop----------------------- 80//---------------------begin void loop----------------------- 81//---------------------begin void loop----------------------- 82void loop(){ 83 serialDoStuff(); 84 if(mouthOnOffNew == mouthOnOffOld){ 85 if(mouthOnOffNew == 1){ 86 blinkFast(); 87 mouthDoStuff(); 88 } 89 if(mouthOnOffNew == 2){ 90 blinkSlow(); 91 } 92 } 93 else if(mouthOnOffNew != mouthOnOffOld){ 94 mouthOnOffNew = mouthOnOffOld; 95 } 96} 97//---------------------end void loop----------------------- 98//---------------------end void loop----------------------- 99//---------------------end void loop----------------------- 100//********************************************************* 101//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 102//********************************************************* 103//---------------------begin serialDoStuff ----------------- 104void serialDoStuff(){ 105 if(Serial.available() > 0){ 106 incomingMouthByte = Serial.read(); 107 mouthOnOffAdjusted = incomingMouthByte - '0'; 108 if(mouthOnOffAdjusted == 1){ 109 Serial.flush(); 110 outgoingMouthByte = 1; 111 Serial.write(outgoingMouthByte); 112 mouthOnOffOld = 1; 113 } 114 else if(mouthOnOffAdjusted == 2){ 115 Serial.flush(); 116 outgoingMouthByte = 2; 117 Serial.write(outgoingMouthByte); 118 mouthOnOffOld = 2; 119 } 120 } 121} 122//---------------------end serialDoStuff----------------- 123//********************************************************* 124//********************************************************* 125//---------------------begin mouthDoStuff ------------------- 126 127void mouthDoStuff(){ 128 int soundDetected; // stores value from sound pin 129 int soundLevel; // converted values that only include 512-1024 130 int servoMap; // conversion from 0-255 to 100-70 131 soundDetected = analogRead(soundPin); // capture audio signal from dc bias circuit 132 if(soundDetected<=512){ // runs when negative amplitude detected 133 soundLevel = (512-soundDetected+512); // takes numbers below 512 and tacks em on top of 512 to create positive amplitudes 134 } 135 else{ 136 soundLevel = soundDetected; // stores positive amplitudes 137 } 138 servoMap = map(soundLevel, 570, 610, 100, 50); // sound map 0-255 is mapped to truncated and inverted servo sweep 100-70 139 if(soundLevel < 700){ 140 if(servoMap < 100){ 141 mouthServo.write(servoMap); 142 Serial.print("soundLevel "); 143 Serial.println(soundLevel); 144 Serial.print(" servoMap "); 145 Serial.println(servoMap); 146 Serial.print(" soundDetected "); 147 Serial.println(soundDetected); 148 } 149 } 150 else{ 151 mouthServo.write(95); 152 Serial.print("soundLevel "); 153 Serial.println(soundLevel); 154 Serial.print(" servoMap "); 155 Serial.println(servoMap); 156 Serial.print(" soundDetected "); 157 Serial.println(soundDetected); 158 } 159 // return soundLevel; 160} 161//// ++++++++++++++++++end mouthDoStuff +++++++++++++++++++++++++++++++++ 162//********************************************************* 163//********************************************************* 164//---------------------begin blink slow------------------- 165void blinkSlow(){ 166unsigned long currentMillis = millis(); 167const long interval1 = 500; 168 169 if(currentMillis - previousMillis >= interval1) { 170 previousMillis = currentMillis; 171 if(ledState == LOW){ 172 ledState = HIGH; 173 } 174 else{ 175 ledState = LOW; 176 } 177 digitalWrite(ledPin, ledState); 178 } 179} 180//---------------------end blink slow------------------- 181//---------------------begin blink fast ------------------- 182void blinkFast(){ 183unsigned long currentMillis = millis(); 184const long interval2 = 75; 185 if(currentMillis - previousMillis >= interval2){ 186 previousMillis = currentMillis; 187 if(ledState == LOW){ 188 ledState = HIGH; 189 } 190 else{ 191 ledState = LOW; 192 } 193 digitalWrite(ledPin, ledState); 194 } 195} 196//---------------------end blink fast ------------------- 197//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 198//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 199//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 200
draft 12102018
c_cpp
latest update finished sorting out page navigation need to clean up colors and word positions will fill in data fetch later
1/* 2last edit sun oct 12 2018 3coded from scratch by wylie jones 4wyliejones@gmail.com 5 6Graves multi arduino build 10/2018 7Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 8two arduino uno's 9slave1 arduino uno to sense sound from graves and echo dot to control mouth 10slave2 arduino uno to control passive sensor array and head servo 11 12sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 13 14 analogue pin speaker + 15 \ / (red from speaker) 16 \ / 17 \ / 18 *--------[=]-----------*---------[=]----------* 19 | resistor \ resistor | 20 | \ | 21 |(red with white) \ |to arduino ground (black with white) 22to arduino 5v+ speaker - 23 (black from speaker) 24 25*/ 26//end notes 27//end notes 28//end notes 29//end notes 30//end notes 31//end notes 32 33 34//********************************************************* 35//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 36//********************************************************* 37 38 39//begin declarations 40//begin declarations 41//begin declarations 42//begin declarations 43//begin declarations 44//begin declarations 45//begin declarations 46 47//#include <TFT.h> 48//#include <Servo.h> 49//#include <stdint.h> 50//#include <SD.h> 51#include <TFTv2.h> 52#include <SPI.h> 53#include <SeeedTouchScreen.h> 54 55//const int PIN_SD_CS = 4; // pin of sd card 56 57TouchScreen ts = TouchScreen(XP, YP, XM, YM); 58int buttonPressed; // stores which button was pressed 59int newButtonTime; // debounce 60int oldButtonTime; // debounce 61int buttonTimeDifference; // debounce 62int debounceTime; // debounce 63int currentScreen; // identifies current screen by adding x y and z 64int zMax = 460; // maximum pressure to detect 65int zMin = 100; // minimum pressure to detect 66int x; // for ones 67int y; // for tens 68int z; // for hundreds 69//end declarations 70//end declarations 71//end declarations 72//end declarations 73//end declarations 74//end declarations 75//end declarations 76//end declarations 77//end declarations 78 79//********************************************************* 80//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 81//********************************************************* 82 83// begin void setup 84// begin void setup 85// begin void setup 86// begin void setup 87// begin void setup 88// begin void setup 89// begin void setup 90// begin void setup 91// begin void setup 92// begin void setup 93// begin void setup 94void setup() { 95Serial.begin(115200); 96 oldButtonTime = millis(); 97 Tft.TFTinit(); // init TFT library 98 TFT_BL_ON; // turn on the background light 99 x = 0; 100 y = 0; 101 z = 0; 102 buttonPressed = 4; 103 debounceTime = 1000; // button debounce in milliseconds 104 currentScreen = 0; 105 callScreen(); 106 107} //void setup() 108// end void setup 109// end void setup 110// end void setup 111// end void setup 112// end void setup 113// end void setup 114// end void setup 115// end void setup 116 117//********************************************************* 118//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 119//********************************************************* 120 121// begin void loop 122// begin void loop 123// begin void loop 124// begin void loop 125// begin void loop 126// begin void loop 127// begin void loop 128// begin void loop 129// begin void loop 130// begin void loop 131// begin void loop 132// begin void loop 133// begin void loop 134// begin void loop 135 136void loop() { 137 tftDetect(); // gather information from touch screen touches 138 buttonTimeDifference = newButtonTime - oldButtonTime; 139 if(debounceTime < buttonTimeDifference){ 140 whatScreen(); 141 callScreen(); 142 oldButtonTime = newButtonTime; 143 showStuff(); // serial prints 144 tftDisplay(); // display x y coordinates on tft display 145 } 146} //void loop() 147 148// end of void loop 149// end of void loop 150// end of void loop 151// end of void loop 152// end of void loop 153// end of void loop 154// end of void loop 155// end of void loop 156// end of void loop 157// end of void loop 158// end of void loop 159// end of void loop 160// end of void loop 161// end of void loop 162// end of void loop 163 164//**************************************************************************************************** 165//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 166//**************************************************************************************************** 167///////////////////////////////////////////////////////////////////////////////////////////////////////// 168///////////////////////////////////////// functions /////////////////////////////////////////////////// 169///////////////////////////////////////////////////////////////////////////////////////////////////////// 170//**************************************************************************************************** 171//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 172//**************************************************************************************************** 173 174//--------------------------begin tftDetect---------------------------------- 175//--------------------------begin tftDetect---------------------------------- 176//--------------------------begin tftDetect---------------------------------- 177//--------------------------begin tftDetect---------------------------------- 178//--------------------------begin tftDetect---------------------------------- 179int tftDetect(){ 180 Point p = ts.getPoint(); 181 if(zMin<p.z && p.z<zMax){ 182 newButtonTime = millis(); 183 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 184 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 185//Button 1 186 if(75<p.x && p.x<140){ 187 if(100<p.y && p.y<164){ 188 buttonPressed = 1; 189 } 190//Button 2 191 if(164<p.y && p.y<240){ 192 buttonPressed = 2; 193 } 194//Button 3 195 if(240<p.y && p.y<310){ 196 buttonPressed = 3; 197 } 198 } 199 } 200//Button 4 201 if(10<p.x && p.x<75){ 202 if(100<p.y && p.y<240){ 203 buttonPressed = 4; 204 } 205 } 206}//void tftDetect 207//--------------------------end tftDetect code---------------------------------- 208//--------------------------end tftDetect code---------------------------------- 209//--------------------------end tftDetect code---------------------------------- 210//--------------------------end tftDetect code---------------------------------- 211//--------------------------end tftDetect code---------------------------------- 212//**************************************************************************************************** 213//**************************************************************************************************** 214//-------------------------- begin whatScreen function ------------------------- 215//-------------------------- begin whatScreen function ------------------------- 216//-------------------------- begin whatScreen function ------------------------- 217//-------------------------- begin whatScreen function ------------------------- 218 219int whatScreen(){ 220 if(x == 0){ 221 if(buttonPressed == 1){ 222 x = x + 1; 223 Serial.println("x + 1"); 224 } 225 if(buttonPressed == 2){ 226 x = x + 2; 227 Serial.println("x + 2"); 228 } 229 if(buttonPressed == 3){ 230 x = x + 3; 231 Serial.println("x + 3"); 232 } 233 if(buttonPressed == 4){ 234 x = 0; 235 Serial.println("x = 0"); 236 } 237 } 238 else if(x >> 0){ 239 if(y == 0){ 240 if(buttonPressed == 1){ 241 y = y + 10; 242 Serial.println("y + 10"); 243 } 244 if(buttonPressed == 2){ 245 y = y + 20; 246 Serial.println("y + 20"); 247 } 248 if(buttonPressed == 3){ 249 y = y + 30; 250 Serial.println("y + 30"); 251 } 252 if(buttonPressed == 4){ 253 x = 0; 254 Serial.println("x = 0"); 255 } 256 } 257 else if (y >> 0){ 258 if(buttonPressed == 1){ 259 z = z + 100; 260 Serial.println("z + 100"); 261 } 262 if(buttonPressed == 2){ 263 z = z + 200; 264 Serial.println("z + 200"); 265 } 266 if(buttonPressed == 3){ 267 z = z + 300; 268 Serial.println("z + 300"); 269 } 270 if(buttonPressed == 4){ 271 if(z == 0){ 272 y = 0; 273 Serial.println("y = 0"); 274 } 275 else if(z >> 0){ 276 z = 0; 277 Serial.println("z = 0"); 278 } 279 } 280 }//y>0 281 }//x>0 282 currentScreen = z+y+x; 283} 284//-------------------------- end whatScreen function ------------------------- 285//-------------------------- end whatScreen function ------------------------- 286//-------------------------- end whatScreen function ------------------------- 287//-------------------------- end whatScreen function ------------------------- 288//-------------------------- end whatScreen function ------------------------- 289 290//**************************************************************************************************** 291//**************************************************************************************************** 292 293//--------------------------begin arduino master data fetch calls---------------------------------- 294// call slave1 arduino for data 295// call slave2 arduino for data 296//--------------------------end arduino master data fetch calls------------------------------------ 297 298//**************************************************************************************************** 299//**************************************************************************************************** 300 301//--------------------------begin tftDisplay code---------------------------------- 302void tftDisplay(){ 303 Point p = ts.getPoint(); 304 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 305 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 306 Tft.fillRectangle(0, 160, 60, 30, BLACK); 307 Tft.drawNumber((p.x), 0, 160, 3, GREEN); 308 Tft.fillRectangle(180, 160, 60, 30, BLACK); 309 Tft.drawNumber((p.y), 180, 160, 3, GREEN); 310 Tft.fillRectangle(80, 160, 60, 30, BLACK); 311 Tft.drawNumber((buttonPressed), 80, 160, 3, GREEN); 312}// void tftDisplay 313//--------------------------end tftDisplay code------------------------------------ 314 315//**************************************************************************************************** 316//**************************************************************************************************** 317 318//-------------------------- begin slave1 data fetch function -------------------------- 319//-------------------------- end slave1 data fetch function -------------------------- 320 321//**************************************************************************************************** 322//**************************************************************************************************** 323 324//-------------------------- begin slave2 data fetch function -------------------------- 325//-------------------------- end slave2 data fetch function ------------------------- 326 327//**************************************************************************************************** 328//**************************************************************************************************** 329 330//-------------------------- begin serial display function -------------------------- 331void showStuff(){ 332 Serial.println("------/ last update /-------"); 333// Serial.println("------begin display-------"); 334 Serial.print("buttonPressed "); 335 Serial.println(buttonPressed); 336 Serial.print("x "); 337 Serial.println(x); 338 Serial.print("y "); 339 Serial.println(y); 340 Serial.print("z "); 341 Serial.println(z); 342 Serial.print("currentScreen "); 343 Serial.println(currentScreen); 344// Serial.println("-------end display--------"); 345 Serial.println(""); 346 Serial.println(""); 347 Serial.println(""); 348 } 349//-------------------------- end serial display function ------------------------- 350 351 352//**************************************************************************************************** 353//**************************************************************************************************** 354 355//--------------------------- Primary screen maps -------------------------------- 356/* 357 358screen 0000 A)Home 359 screen 0001 a)settings 360 screen 0011 -brightness 361 screen 0011 -contrast 362 screen 0011 -screen lock time out 363 screen 0001 b)sensor monitors 364 screen 0021 -pir 365 screen 0121 *report pir detection 366 screen 0021 -sound 367 screen 0221 *sense alexa sound 368 screen 0221 *sense graves sound 369 screen 0221 *report mouth servo position 370 screen 0221 *adjust sensitivity? 371 screen 0021 -head potentiometer 372 screen 0021 -bluetooth 373 screen 0001 c)bluetooth 374 screen 0031 -on 375 screen 0031 -off 376 screen 0031 -monitor 377screen 0000 B)Mouth Control 378 screen 0002 a)test button 379 screen 0012 -open 380 screen 0012 -close 381 screen 0012 -push button chicken switch 382 screen 0002 b)sound sensors on/off 383 screen 0022 -alexa sense 384 screen 0122 *on 385 screen 0122 *off 386 screen 0122 *monitor sensor 387 screen 0022 -graves sense 388 screen 0222 *on 389 screen 0222 *off 390 screen 0222 *monitor sensors 391 screen 0002 c)sound sensor status 392 screen 0032 -alexa 393 screen 0032 -graves 394screen 0000 C)Head Control 395 screen 0003 a)pir on/off 396 screen 0013 -on 397 screen 0013 -off 398 screen 0013 -sensor 399 screen 0003 b)manual point 400 screen 0023 -slider 401*/ 402//**************************************************************************************************** 403//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 404//**************************************************************************************************** 405//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 406//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 407//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 408//**************************************************************************************************** 409//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 410//**************************************************************************************************** 411 412//-------------------------- begin callScreen function ------------------------- 413//-------------------------- begin callScreen function ------------------------- 414//-------------------------- begin callScreen function ------------------------- 415//-------------------------- begin callScreen function ------------------------- 416//-------------------------- begin callScreen function ------------------------- 417//-------------------------- begin callScreen function ------------------------- 418//-------------------------- begin callScreen function ------------------------- 419//-------------------------- begin callScreen function ------------------------- 420//-------------------------- begin callScreen function ------------------------- 421//-------------------------- begin callScreen function ------------------------- 422//-------------------------- begin callScreen function ------------------------- 423 424int callScreen(){ 425 Tft.fillRectangle(0, 0, 240, 320, BLACK); 426 427//<><><><><><><><><><><><><><><><><><><><><><><><> 428//<><><><><><><><> begin screen 0000 master <><><><><><><><> 429//<><><><><><><><><><><><><><><><><><><><><><><><> 430if(currentScreen == 0){ 431 // " " 432 Tft.drawString("GRAVES",0,5,4, GREEN); 433 Tft.drawString("INTERFACE",10,50,4,GREEN); 434 Tft.drawString("Home", 80,130, 3, GREEN); 435 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 436 Tft.drawString("Head Control", 10, 260, 3, GREEN); 437} 438//<><><><><><><><><><><><><><><><><><><><><><><><> 439//<><><><><><><><> end screen 0000 master <><><><><><><><><> 440//<><><><><><><><><><><><><><><><><><><><><><><><> 441 442//<><><><><><><><><><><><><><><><><><><><><><><><> 443//<><><><><><><><> begin screen 0001 <><><><><><><><> 444//<><><><><><><><><><><><><><><><><><><><><><><><> 445 if(currentScreen == 1){ 446 // " " 447 Tft.drawString("MEGA 2560",00,5,4,BLUE); 448 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 449 Tft.drawString("Settings", 10,130, 3, BLUE); 450 Tft.drawString("Sensors", 20, 195, 3, BLUE); 451 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 452 Tft.drawString("<", 0, 160, 3, GREEN); // back button 453} 454//<><><><><><><><><><><><><><><><><><><><><><><><> 455//<><><><><><><><> end screen 0001 <><><><><><><><><> 456//<><><><><><><><><><><><><><><><><><><><><><><><> 457 458//<><><><><><><><><><><><><><><><><><><><><><><><> 459//<><><><><><><><> begin screen 0011 <><><><><><><><> 460//<><><><><><><><><><><><><><><><><><><><><><><><> 461 if(currentScreen == 11){ 462 // " " 463 Tft.drawString("MEGA 2560",00,5,4,BLUE); 464 Tft.drawString("SETTINGS",10,50,4,YELLOW); 465 Tft.drawString("Brightness", 80,130, 3, BLUE); 466 Tft.drawString("Contrast", 05, 195, 3, GREEN); 467 Tft.drawString("Timeout", 10, 260, 3, GREEN); 468 Tft.drawString("<", 0, 160, 3, GREEN); // back button 469} 470 471//<><><><><><><><><><><><><><><><><><><><><><><><> 472//<><><><><><><><> end screen 0011 <><><><><><><><><> 473//<><><><><><><><><><><><><><><><><><><><><><><><> 474 475//<><><><><><><><><><><><><><><><><><><><><><><><> 476//<><><><><><><><> begin screen 0021 <><><><><><><><> 477//<><><><><><><><><><><><><><><><><><><><><><><><> 478 if(currentScreen == 21){ 479 // " " 480 Tft.drawString("MEGA 2560",00,5,4,BLUE); 481 Tft.drawString("SENSORS",10,50,4,YELLOW); 482 Tft.drawString("PIR Array", 80,130, 3, BLUE); 483 Tft.drawString("Sound", 05, 195, 3, GREEN); 484 Tft.drawString("Head Position", 10, 260, 3, GREEN); 485 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 486 Tft.drawString("<", 0, 160, 3, GREEN); // back button 487} 488//<><><><><><><><><><><><><><><><><><><><><><><><> 489//<><><><><><><><> end screen 0021 <><><><><><><><><> 490//<><><><><><><><><><><><><><><><><><><><><><><><> 491 492//<><><><><><><><><><><><><><><><><><><><><><><><> 493//<><><><><><><><> begin screen 0121 <><><><><><><><> 494//<><><><><><><><><><><><><><><><><><><><><><><><> 495 if(currentScreen == 121){ 496 // " " 497 Tft.drawString("PIR",0,5,4,BLUE); 498 Tft.drawString("ARRAY",10,50,4,YELLOW); 499 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 500 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 501 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 502 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 503 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 504 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 505 Tft.drawString("<", 0, 160, 3, GREEN); // back button 506} 507//<><><><><><><><><><><><><><><><><><><><><><><><> 508//<><><><><><><><> end screen 0121 <><><><><><><><><> 509//<><><><><><><><><><><><><><><><><><><><><><><><> 510 511//<><><><><><><><><><><><><><><><><><><><><><><><> 512//<><><><><><><><> begin screen 0221 <><><><><><><><> 513//<><><><><><><><><><><><><><><><><><><><><><><><> 514 if(currentScreen == 221){ 515 // " " 516 Tft.drawString("SOUND",0,5,4,BLUE); 517 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 518 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 519 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 520 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 521 Tft.drawString("<", 0, 160, 3, GREEN); // back button 522} 523//<><><><><><><><><><><><><><><><><><><><><><><><> 524//<><><><><><><><> end screen 0221 <><><><><><><><><> 525//<><><><><><><><><><><><><><><><><><><><><><><><> 526 527//<><><><><><><><><><><><><><><><><><><><><><><><> 528//<><><><><><><><> begin screen 0031 <><><><><><><><> 529//<><><><><><><><><><><><><><><><><><><><><><><><> 530 if(currentScreen == 31){ 531 // " " 532 Tft.drawString("Bluetooth",0,5,4,BLUE); 533 Tft.drawString("Control",10,50,4,YELLOW); 534 Tft.drawString("On", 80,130, 3, BLUE); 535 Tft.drawString("Off", 05, 195, 3, GREEN); 536 Tft.drawString("Monitor", 10, 260, 3, GREEN); 537 Tft.drawString("<", 0, 160, 3, GREEN); // back button 538} 539//<><><><><><><><><><><><><><><><><><><><><><><><> 540//<><><><><><><><> end screen 0031 <><><><><><><><><> 541//<><><><><><><><><><><><><><><><><><><><><><><><> 542 543//<><><><><><><><><><><><><><><><><><><><><><><><> 544//<><><><><><><><> begin screen 0002 <><><><><><><><> 545//<><><><><><><><><><><><><><><><><><><><><><><><> 546 if(currentScreen == 2){ 547 // " " 548 Tft.drawString("Mouth",0,5,4,BLUE); 549 Tft.drawString("Control",10,50,4,YELLOW); 550 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 551 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 552 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 553 Tft.drawString("<", 0, 160, 3, GREEN); // back button 554} 555//<><><><><><><><><><><><><><><><><><><><><><><><> 556//<><><><><><><><> end screen 0002 <><><><><><><><><> 557//<><><><><><><><><><><><><><><><><><><><><><><><> 558 559 560//<><><><><><><><><><><><><><><><><><><><><><><><> 561//<><><><><><><><> begin screen 0012 <><><><><><><><> 562//<><><><><><><><><><><><><><><><><><><><><><><><> 563 if(currentScreen == 12){ 564 // " " 565 Tft.drawString("Jaw Test",0,5,4,BLUE); 566 Tft.drawString("Operations",10,50,4,YELLOW); 567 Tft.drawString("Open", 80,130, 3, BLUE); 568 Tft.drawString("Close", 05, 195, 3, GREEN); 569 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 570 Tft.drawString("<", 0, 160, 3, GREEN); // back button 571} 572//<><><><><><><><><><><><><><><><><><><><><><><><> 573//<><><><><><><><> end screen 0012 <><><><><><><><><> 574//<><><><><><><><><><><><><><><><><><><><><><><><> 575 576 577//<><><><><><><><><><><><><><><><><><><><><><><><> 578//<><><><><><><><> begin screen 0022 <><><><><><><><> 579//<><><><><><><><><><><><><><><><><><><><><><><><> 580 if(currentScreen == 22){ 581 // " " 582 Tft.drawString("Sound",0,5,4,BLUE); 583 Tft.drawString("Sensors",10,50,4,YELLOW); 584 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 585 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 586 Tft.drawString("Monitor", 10, 260, 3, GREEN); 587 Tft.drawString("<", 0, 160, 3, GREEN); // back button 588} 589//<><><><><><><><><><><><><><><><><><><><><><><><> 590//<><><><><><><><> end screen 0022 <><><><><><><><><> 591//<><><><><><><><><><><><><><><><><><><><><><><><> 592 593 594 595//<><><><><><><><><><><><><><><><><><><><><><><><> 596//<><><><><><><><> begin screen 0122 <><><><><><><><> 597//<><><><><><><><><><><><><><><><><><><><><><><><> 598 if(currentScreen == 122){ 599 // " " 600 Tft.drawString("Alexa Sense",0,5,4,BLUE); 601 Tft.drawString("Operations",10,50,4,YELLOW); 602 Tft.drawString("On", 80,130, 3, BLUE); 603 Tft.drawString("Off", 05, 195, 3, GREEN); 604 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 605 Tft.drawString("<", 0, 160, 3, GREEN); // back button 606} 607//<><><><><><><><><><><><><><><><><><><><><><><><> 608//<><><><><><><><> end screen 0122 <><><><><><><><><> 609//<><><><><><><><><><><><><><><><><><><><><><><><> 610 611//<><><><><><><><><><><><><><><><><><><><><><><><> 612//<><><><><><><><> begin screen 0222 <><><><><><><><> 613//<><><><><><><><><><><><><><><><><><><><><><><><> 614 if(currentScreen == 222){ 615 // " " 616 Tft.drawString("Graves Sense",0,5,4,BLUE); 617 Tft.drawString("Operations",10,50,4,YELLOW); 618 Tft.drawString("On", 80,130, 3, BLUE); 619 Tft.drawString("Off", 05, 195, 3, GREEN); 620 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 621 Tft.drawString("<", 0, 160, 3, GREEN); // back button 622} 623//<><><><><><><><><><><><><><><><><><><><><><><><> 624//<><><><><><><><> end screen 0222 <><><><><><><><><> 625//<><><><><><><><><><><><><><><><><><><><><><><><> 626 627//<><><><><><><><><><><><><><><><><><><><><><><><> 628//<><><><><><><><> begin screen 0032 <><><><><><><><> 629//<><><><><><><><><><><><><><><><><><><><><><><><> 630 if(currentScreen == 32){ 631 // " " 632 Tft.drawString("Sound Sense",0,5,4,BLUE); 633 Tft.drawString("Monitors",10,50,4,YELLOW); 634 Tft.drawString("Alexa", 80,130, 3, BLUE); 635 Tft.drawString("Graves", 05, 195, 3, GREEN); 636 Tft.drawString("<", 0, 160, 3, GREEN); // back button 637} 638//<><><><><><><><><><><><><><><><><><><><><><><><> 639//<><><><><><><><> end screen 0032 <><><><><><><><><> 640//<><><><><><><><><><><><><><><><><><><><><><><><> 641 642//<><><><><><><><><><><><><><><><><><><><><><><><> 643//<><><><><><><><> begin screen 0003 <><><><><><><><> 644//<><><><><><><><><><><><><><><><><><><><><><><><> 645 if(currentScreen == 3){ 646 // " " 647 Tft.drawString("Head Control",0,5,4,BLUE); 648 Tft.drawString("Operations",10,50,4,YELLOW); 649 Tft.drawString("PIR Array", 80,130, 3, BLUE); 650 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 651 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 652 Tft.drawString("<", 0, 160, 3, GREEN); // back button 653} 654//<><><><><><><><><><><><><><><><><><><><><><><><> 655//<><><><><><><><> end screen 0003 <><><><><><><><><> 656//<><><><><><><><><><><><><><><><><><><><><><><><> 657 658//<><><><><><><><><><><><><><><><><><><><><><><><> 659//<><><><><><><><> begin screen 0013 <><><><><><><><> 660//<><><><><><><><><><><><><><><><><><><><><><><><> 661 if(currentScreen == 13){ 662 // " " 663 Tft.drawString("PIR Control",0,5,4,BLUE); 664 Tft.drawString("Operations",10,50,4,YELLOW); 665 Tft.drawString("On", 80,130, 3, BLUE); 666 Tft.drawString("Off", 05, 195, 3, GREEN); 667 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 668 Tft.drawString("<", 0, 160, 3, GREEN); // back button 669} 670//<><><><><><><><><><><><><><><><><><><><><><><><> 671//<><><><><><><><> end screen 0013 <><><><><><><><><> 672//<><><><><><><><><><><><><><><><><><><><><><><><> 673 674//<><><><><><><><><><><><><><><><><><><><><><><><> 675//<><><><><><><><> begin screen 0023 <><><><><><><><> 676//<><><><><><><><><><><><><><><><><><><><><><><><> 677 if(currentScreen == 23){ 678 // " " 679 Tft.drawString("Head Control",0,5,4,BLUE); 680 Tft.drawString("Manual Point",10,50,4,YELLOW); 681 Tft.drawString("Slider", 80,130, 3, BLUE); 682 Tft.drawString("<", 0, 160, 3, GREEN); // back button 683} 684//<><><><><><><><><><><><><><><><><><><><><><><><> 685//<><><><><><><><> end screen 0023 <><><><><><><><><> 686//<><><><><><><><><><><><><><><><><><><><><><><><> 687 688 689////<><><><><><><><><><><><><><><><><><><><><><><><> 690////<><><><><><><><> begin screen lost <><><><><><><><> 691////<><><><><><><><><><><><><><><><><><><><><><><><> 692// else if(currentScreen){ 693// // " " 694// Tft.drawString("Screen not",0,5,3,BLUE); 695// Tft.drawString("found. Please",40,50,3,YELLOW); 696// Tft.drawString("use the back", 80,130, 3, BLUE); 697// Tft.drawString("button to", 05, 195, 3, GREEN); 698// Tft.drawString("return to fun", 10, 260, 3, GREEN); 699// Tft.drawString("<", 0, 160, 3, GREEN); // back button 700//} 701////<><><><><><><><><><><><><><><><><><><><><><><><> 702////<><><><><><><><> end screen lost <><><><><><><><><> 703////<><><><><><><><><><><><><><><><><><><><><><><><> 704 705}// callScreen 706//-------------------------- end callScreen function ------------------------- 707//-------------------------- end callScreen function ------------------------- 708//-------------------------- end callScreen function ------------------------- 709//-------------------------- end callScreen function ------------------------- 710//-------------------------- end callScreen function ------------------------- 711//-------------------------- end callScreen function ------------------------- 712//-------------------------- end callScreen function ------------------------- 713//-------------------------- end callScreen function ------------------------- 714//-------------------------- end callScreen function ------------------------- 715//-------------------------- end callScreen function ------------------------- 716//-------------------------- end callScreen function ------------------------- 717//-------------------------- end callScreen function ------------------------- 718//-------------------------- end callScreen function ------------------------- 719 720 721//**************************************************************************************************** 722//**************************************************************************************************** 723 724 725 726 727 728 729 730//**************************************************************************************************** 731//**************************************************************************************************** 732 733// fin
24102018 mouth code
c_cpp
New code for the mouth arduino is getting ready to accommodate a new button group and needs threshold adjustment for both graves and echo. new dc bias circuit built with proper resistors thus the need for code adjustment
1/* 224102018 3 4gravesunomouth 5 6graves project 7arduino Uno 8Slave 1 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17 18sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 19 20 analogue pin speaker + 21 \(yellow signal / (red from speaker) 22 10k Ohm \ wire) / 23 resistor \ / 24 *--------/\\/\\/---------*---------/\\/\\/--------* 25 | \ 10k Ohm | 26 | \ resistor | 27 |(red with white) \ |to arduino ground (black with white) 28to arduino 5v+ -)|- 29 \ 100uF 16v 30 \ capacitor 31 \\ 32 \\ 33 speaker - 34 (black from speaker) 35 36*/ 37#include <Servo.h> 38#include <SPI.h> 39 40//---------------------begin declarations----------------------- 41// for servo actions 42Servo mouthServo; 43 44// for gathering and mapping sound data 45int soundPinGraves=A3; // incoming lead from graves dc bias circuit 46int soundPinEcho=A4; // incoming lead from echo dc bias circuit 47int soundDetectedEcho; // stores value from sound pin 48int soundLevelEcho; // converted values that only include 512-1024 49int soundMapEcho; // conversion from 512-1024 to 0-255 50int servoMapEcho; // conversion from 0-255 to 100-70 51int soundDetectedGraves; // stores value from sound pin 52int soundLevelGraves; // converted values that only include 512-1024 53int soundMapGraves; // conversion from 512-1024 to 0-255 54int servoMapGraves; // conversion from 0-255 to 100-70 55 56// communication 57char incomingMouthByte; // for incoming serial data 58char outgoingMouthByte; // for a bit more talkative serial data 59int mouthOnOffNew; // stores mouth state from serial connection 60int mouthOnOffOld; // stores mouth state from serial connection 61int mouthOnOffAdjusted; // value adjusted by 48 for ascii 62 63// for blinking 64const int ledPin = LED_BUILTIN;// the number of the LED pin 65int ledState = LOW; // ledState used to set the LED 66unsigned long previousMillis = 0; // will store last time LED was updated 67//---------------------end declarations----------------------- 68//********************************************************* 69//********************************************************* 70//---------------------begin void setup----------------------- 71//---------------------begin void setup----------------------- 72//---------------------begin void setup----------------------- 73void setup(){ 74 delay(1000); 75 Serial.begin(9600); 76 mouthServo.attach(6); 77 incomingMouthByte = 0; // for incoming serial data 78 outgoingMouthByte = 0; // for a little more talkative serial data 79 mouthOnOffNew = 1; // stores mouth state from serial connection 80 mouthOnOffOld = 1; // stores mouth state from serial connection 81 pinMode(ledPin, OUTPUT); 82 pinMode(soundPinEcho, INPUT); 83 pinMode(soundPinGraves, INPUT); 84} 85//---------------------end void setup----------------------- 86//---------------------end void setup----------------------- 87//---------------------end void setup----------------------- 88//********************************************************** 89//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 90//********************************************************** 91//---------------------begin void loop----------------------- 92//---------------------begin void loop----------------------- 93//---------------------begin void loop----------------------- 94void loop(){ 95 serialDoStuff(); 96 if(mouthOnOffNew == mouthOnOffOld){ 97 if(mouthOnOffNew == 1){ 98 blinkFast(); 99 mouthDoStuffGraves(); 100 mouthDoStuffEcho(); 101 } 102 if(mouthOnOffNew == 2){ 103 mouthDoStuffEcho(); 104 blinkSlow(); 105 } 106 if(mouthOnOffNew == 3){ 107 blinkSlow(); 108 mouthDoStuffGraves(); 109 } 110 if(mouthOnOffNew == 4){ 111 } 112 if(mouthOnOffNew == 5){ 113 } 114 if(mouthOnOffNew == 6){ 115 } 116 if(mouthOnOffNew == 7){ 117 } 118 if(mouthOnOffNew == 8){ 119 } 120 } 121 else if(mouthOnOffNew != mouthOnOffOld){ 122 mouthOnOffNew = mouthOnOffOld; 123 } 124} 125//---------------------end void loop----------------------- 126//---------------------end void loop----------------------- 127//---------------------end void loop----------------------- 128//********************************************************* 129//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 130//********************************************************* 131//---------------------begin serialDoStuff ----------------- 132void serialDoStuff(){ 133 if(Serial.available() > 0){ 134 incomingMouthByte = Serial.read(); 135 mouthOnOffAdjusted = incomingMouthByte - '0'; 136 if(mouthOnOffAdjusted == 1){ 137 Serial.flush(); 138 outgoingMouthByte = 1; 139 Serial.write(outgoingMouthByte); 140 mouthOnOffOld = 1; 141 } 142 else if(mouthOnOffAdjusted == 2){ 143 Serial.flush(); 144 outgoingMouthByte = 2; 145 Serial.write(outgoingMouthByte); 146 mouthOnOffOld = 2; 147 } 148 else if(mouthOnOffAdjusted == 3){ 149 Serial.flush(); 150 outgoingMouthByte = 3; 151 Serial.write(outgoingMouthByte); 152 mouthOnOffOld = 3; 153 } 154 else if(mouthOnOffAdjusted == 4){ 155 Serial.flush(); 156 outgoingMouthByte = 4; 157 Serial.write(outgoingMouthByte); 158 mouthOnOffOld = 4; 159 } 160 else if(mouthOnOffAdjusted == 5){ 161 Serial.flush(); 162 outgoingMouthByte = 5; 163 Serial.write(outgoingMouthByte); 164 mouthOnOffOld = 5; 165 } 166 else if(mouthOnOffAdjusted == 6){ 167 Serial.flush(); 168 outgoingMouthByte = 6; 169 Serial.write(outgoingMouthByte); 170 mouthOnOffOld = 6; 171 } 172 else if(mouthOnOffAdjusted == 7){ 173 Serial.flush(); 174 outgoingMouthByte = 7; 175 Serial.write(outgoingMouthByte); 176 mouthOnOffOld = 7; 177 } 178 else if(mouthOnOffAdjusted == 8){ 179 Serial.flush(); 180 outgoingMouthByte = 8; 181 Serial.write(outgoingMouthByte); 182 mouthOnOffOld = 8; 183 } 184 } 185 Serial.println(analogRead(soundPinGraves)); 186 Serial.print(" "); 187 Serial.println(analogRead(soundPinEcho)); 188// Serial.print("raw LevelGraves "); 189// Serial.print(analogRead(soundPinGraves)); 190// Serial.print("soundLevelGraves "); 191// Serial.println(soundLevelGraves); 192// Serial.print(" servoMapGraves "); 193// Serial.println(servoMapGraves); 194// Serial.print("soundDetectedGraves "); 195// Serial.println(soundDetectedGraves); 196} 197//---------------------end serialDoStuff----------------- 198//********************************************************* 199//********************************************************* 200//---------------------begin mouthDoStuffGraves ------------------- 201 202void mouthDoStuffGraves(){ 203 int soundDetectedGraves; // stores value from sound pin 204 int soundLevelGraves; // converted values that only include 512-1024 205 int servoMapGraves; // conversion from 0-255 to 100-70 206 207 208 soundDetectedGraves = analogRead(soundPinGraves); // capture audio signal from dc bias circuit 209 if(soundDetectedGraves<=512){ // runs when negative amplitude detected 210 soundLevelGraves = (512-soundDetectedGraves+512); // takes numbers below 512 and tacks em on top of 512 to create positive amplitudes 211 } 212 else{ 213 soundLevelGraves = soundDetectedGraves; // stores positive amplitudes 214 } 215 216 servoMapGraves = map(soundLevelGraves, 570, 610, 100, 50); // sound map 0-255 is mapped to truncated and inverted servo sweep 100-70 217 if(soundLevelGraves < 700 ){ 218 if(servoMapGraves < 100){ 219 mouthServo.write(servoMapGraves); 220 } 221 } 222 else{ 223 mouthServo.write(95); 224 } 225 // return soundLevelGraves; 226} 227 228//// ++++++++++++++++++end mouthDoStuffGraves +++++++++++++++++++++++++++++++++ 229//********************************************************* 230//********************************************************* 231//---------------------begin mouthDoStuffEcho ------------------- 232 233void mouthDoStuffEcho(){ 234 int soundDetectedEcho; // stores value from sound pin 235 int soundLevelEcho; // converted values that only include 512-1024 236 int servoMapEcho; // conversion from 0-255 to 100-70 237 238 239 soundDetectedEcho = analogRead(soundPinEcho); // capture audio signal from dc bias circuit 240 if(soundDetectedEcho<=512){ // runs when negative amplitude detected 241 soundLevelEcho = (512-soundDetectedEcho+512); // takes numbers below 512 and tacks em on top of 512 to create positive amplitudes 242 } 243 else{ 244 soundLevelEcho = soundDetectedEcho; // stores positive amplitudes 245 } 246 247 servoMapEcho = map(soundLevelEcho, 570, 610, 100, 50); // sound map 0-255 is mapped to truncated and inverted servo sweep 100-70 248 if(soundLevelEcho < 700 ){ 249 if(servoMapEcho < 100){ 250 mouthServo.write(servoMapEcho); 251 } 252 } 253 else{ 254 mouthServo.write(95); 255 } 256 // return soundLevelEcho; 257} 258 259//// ++++++++++++++++++end mouthDoStuffEcho +++++++++++++++++++++++++++++++++ 260//********************************************************* 261//********************************************************* 262//---------------------begin blink slow------------------- 263void blinkSlow(){ 264unsigned long currentMillis = millis(); 265const long interval1 = 500; 266 267 if(currentMillis - previousMillis >= interval1) { 268 previousMillis = currentMillis; 269 if(ledState == LOW){ 270 ledState = HIGH; 271 } 272 else{ 273 ledState = LOW; 274 } 275 digitalWrite(ledPin, ledState); 276 } 277} 278//---------------------end blink slow------------------- 279//---------------------begin blink fast ------------------- 280void blinkFast(){ 281unsigned long currentMillis = millis(); 282const long interval2 = 75; 283 if(currentMillis - previousMillis >= interval2){ 284 previousMillis = currentMillis; 285 if(ledState == LOW){ 286 ledState = HIGH; 287 } 288 else{ 289 ledState = LOW; 290 } 291 digitalWrite(ledPin, ledState); 292 } 293} 294//---------------------end blink fast ------------------- 295//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 296//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 297//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 298 299
22102018 graves uno head code late night
c_cpp
head is tracking better. head on off function control from tft is successful! added ramped speeds to motor control. mostly debugged. needs a trim. could talk a bit more and use its outgoing skills.
1/* 222102018 3 4gravesunohead 5 6graves project 7arduino Uno 8Slave 2 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17 18Graves' head originally had a motor to look left and right. The routine failed; so, the built in 19routine was scrapped in favor of a L298n motor controller coupled through the arduino to a pir 20array added to the serving tray. The result is a passive tracking abilty to 21face the skull towards the direction of the triggered sensor. CREEPY. 22 23the pir sensors are hc-sr501 type passive infrared recievers with their bug-eye lenses removed 24I bypassed R13 and R33 on all 5 sensors to decrease the hadwired delay. 25 26the sensors need the addition of a pull-down reisistor circuit. The sensors send voltage to the pin 27on the arduino when something is detected. When nothing is detected and the pins are left to float, 28the system glitches with multiple false triggers. Thus, a pull down resistor is needed for every sensor 29to ensure the state read is a 0. 30 31 32signal in from pir signal continues to arduino digital pin 33--------------------*----------------------------------------- 34 \\ 35 tap into signal wire \\ 36 \ 10k Ohm 37 \ resistor to ground (all bundled together to ground) 38 *-------/\\/\\/------------------------ 39 40 41*/ 42 43 44// L298n motor controller code 45// connect motor controller pins to Arduino digital pins 46// motor one 47int enA = 10; 48int in1 = 8; 49int in2 = 9; 50// L298n motor controller code 51 52// pot switches 53int potControlPin = A1; // analog pin used to connect the controller potentiometer 54//int valControl; // variable to read the value from the analog pin for control input 55int potControl = 0; // variable to store the servo position from the controller pot switch 56int potPositionPin = A0; // analog pin used to connect the position monitoring potentiometer 57int valPosition; // variable to read the value from the analog pin connected to position monitor 58int potPosition = 0; // variable to store the servo position of the monitoring pot switch 59// pot switches 60int detectedPosition; // variable to store info 61boolean pirStatus; 62 63int servangle = 0; // servo angle variable 64int pirNo[] = {3,4,5,6,7}; // pir pin numbers 65int pirPrevLow[] = {1,1,1,1,1}; // previously low flag set to true 66int pirPrevUsed[] = {0,0,0,0,0}; // has pir been on used before going low 67unsigned long pirPrevMillis[] = {0,0,0,0,0}; // has pir been on used before going low 68unsigned long pirCurMillis[] = {0,0,0,0,0}; // has pir been on used before going low 69int pirPos[] = {10,60,100,140,170}; // positions for servo (0-180) 70int curPosPir = 0; 71int pirPin = 3; 72int senseState3; 73int senseState4; 74int senseState5; 75int senseState6; 76int senseState7; 77 78 unsigned long currentMillis; 79unsigned long time; 80long ignoreTime; 81// for blinking 82const int ledPin = LED_BUILTIN;// the number of the LED pin 83int ledState = LOW; // ledState used to set the LED 84unsigned long previousMillis = 0; // will store last time LED was updated 85 86long interval = 1; // interval at which to move servos (milliseconds) 87 88char incomingHeadByte; 89char outgoingHeadByte; 90int headOnOffAdjusted; 91int headOnOffOld; 92int headOnOffNew; 93 94 95void setup() { 96 delay(500); 97 Serial.begin(9600); 98 incomingHeadByte = 0; // for incoming serial data 99 outgoingHeadByte = 0; // for a bit more talkative serial data 100 headOnOffAdjusted = 1; 101 headOnOffOld = 1; // stores head state from serial connection 102 headOnOffNew = 1; // stores head state from serial connection 103 104 105 time = millis(); 106 // motor control setup code 107 // set all the motor control pins to outputs 108 pinMode(enA, OUTPUT); 109 pinMode(in1, OUTPUT); 110 pinMode(in2, OUTPUT); 111 // motor control setup code 112 pinMode(LED_BUILTIN, OUTPUT); 113 pinMode(pirNo[3], INPUT); 114 pinMode(pirNo[4], INPUT); 115 pinMode(pirNo[5], INPUT); 116 pinMode(pirNo[6], INPUT); 117 pinMode(pirNo[7], INPUT); 118 119 // blink led to denote ready 120 blinkSlow(); 121} 122//---------------------end void setup----------------------- 123//---------------------end void setup----------------------- 124//---------------------end void setup----------------------- 125 126//---------------------begin void loop----------------------- 127//---------------------begin void loop----------------------- 128//---------------------begin void loop----------------------- 129 130void loop(){ 131 serialDoStuff(); 132 if(headOnOffNew == headOnOffOld){ 133 if(headOnOffNew == 1){ 134 sensePositionFunction(); 135 headTurn(); 136 pirReport(); 137 } 138 if(headOnOffNew == 2){ 139 previousMillis = currentMillis; 140 // do Thing C 141 // turn motor off 142 analogWrite(enA, 0); 143 digitalWrite(in1, LOW); 144 digitalWrite(in2, LOW); 145 outgoingHeadByte = '-'; 146 Serial.write(outgoingHeadByte); 147 Serial.println(""); 148 } 149 } 150 else if(headOnOffNew != headOnOffOld){ 151 headOnOffNew = headOnOffOld; 152 } 153} 154 155//---------------------end void loop----------------------- 156//---------------------end void loop----------------------- 157//---------------------end void loop----------------------- 158 159 160//********************************************************* 161//********************************************************* 162 163//---------------------begin serialDoStuff ----------------- 164void serialDoStuff(){ 165 if(Serial.available() > 0){ 166 incomingHeadByte = Serial.read(); 167 headOnOffAdjusted = incomingHeadByte - '0'; 168 if(headOnOffAdjusted == 1){ 169 Serial.flush(); 170// outgoingHeadByte = 1; 171// Serial.write(outgoingHeadByte); 172 headOnOffOld = 1; 173 } 174 else if(headOnOffAdjusted == 2){ 175 Serial.flush(); 176// outgoingHeadByte = 2; 177// Serial.write(outgoingHeadByte); 178 headOnOffOld = 2; 179 } 180 } 181} 182//---------------------end serialDoStuff----------------- 183 184//********************************************************* 185//********************************************************* 186//********************************************************* 187//********************************************************* 188// ++++++++++++++++++begin PIR function +++++++++++++++++++++++++++++++ 189 190void sensePositionFunction(){ 191 ignoreTime = 4000; 192 for(int j=0;j<5;j++){ // do this for each PIR in the array 193 pirPin=pirNo[j]; 194 pirCurMillis[j] = millis(); 195 pirStatus = digitalRead(pirPin); 196 if(pirStatus == HIGH){ // while cycling through the array if pirNo[j] is HIGH, do this 197 if(pirPrevLow[j]){ // and If pirNo[j] was previously low, do this 198 if(curPosPir != pirPin && pirPrevUsed[j] == 0){ // if pirNo[j] is HIGH and different than curPosPir, move to new position 199 curPosPir = pirPin; // keep current PIR 200 pirPrevUsed[j] = 1; 201 if(ignoreTime > pirCurMillis[j] - pirPrevMillis[j]){ // example 4 sec > 30 sec - 28 sec 202 Serial.print(" pin skipped for being too early "); 203 Serial.println(curPosPir); 204 } 205 else if(ignoreTime <= pirCurMillis[j] - pirPrevMillis[j]){ // example 4 sec < 38 sec - 32 sec 206 detectedPosition = pirPin; 207 pirPrevMillis[j] = millis(); 208 } 209// return detectedPosition; 210 } 211 pirPrevLow[j] = 0; // pir is now recorded as not low 212 } 213 } 214 else{ 215 pirPrevLow[j] = 1; // pir is now recorded as low 216 pirPrevUsed[j] = 0; 217 } 218 } // end j number of pirs loop 219Serial.print(" detectedPosition "); 220Serial.println(detectedPosition); 221} 222//+++++++++++++++++++++++end PIR function +++++++++++++++++++++++++++++++ 223void pirReport(){ 224 senseState3 = digitalRead(3); 225 226// Serial.println(millis()/1000); 227 Serial.print(" 3"); 228 Serial.print(senseState3); 229 230 231 delay(5); 232 senseState4 = digitalRead(4); 233 234// Serial.println(millis()/1000); 235 Serial.print(" 4"); 236 Serial.print(senseState4); 237 238 239 senseState5 = digitalRead(5); 240 241// Serial.println(millis()/1000); 242 Serial.print(" 5"); 243 Serial.print(senseState5); 244 245 246 senseState6 = digitalRead(6); 247 248// Serial.println(millis()/1000); 249 Serial.print(" 6"); 250 Serial.print(senseState6); 251 252 253 senseState7 = digitalRead(7); 254 255// Serial.println(millis()/1000); 256 Serial.print(" 7"); 257 Serial.print(senseState7); 258 259 260 // delay(5); 261//clear screen 262 Serial.println(""); 263// Serial.println(""); 264// Serial.println(""); 265// Serial.println(""); 266// Serial.println(""); 267// Serial.println(""); 268// Serial.println(""); 269// 270// delay(50); 271 } 272//********************************************************* 273//********************************************************* 274 275//---------------------begin headTurn ------------------- 276 277void headTurn() { 278currentMillis = millis(); 279 280 long motorStep = 50; // time for motor to run before switching off 281 282 // begin potservo section for potentiometer control 283// int valControl = analogRead(A0); // reads the value of the potentiometer (value between 0 and 1023) 284// valControl = map(valControl, 0, 1023, 0, 10); // first set refers to pot min/max second is servo map 285 int valControl = detectedPosition; // reads the value of the potentiometer (value between 0 and 1023) 286 valControl = map(valControl, 7, 3, 1, 5); // first number set refers to pir array pins, second is servo map 287 int valPosition = analogRead(A0); // reads value of position pot 288 valPosition = map(valPosition, 350, 650, 5, 1); // first min second max read from position potentiometer 289// Serial.print("control "); 290// Serial.println(valControl); 291 Serial.print(" valControl "); 292 Serial.println(valControl); 293 Serial.print(" reported position "); 294 Serial.println(valPosition); 295 Serial.print(" position "); 296 Serial.println(analogRead(A1)); 297// Serial.print(" raw pot pos "); 298// Serial.println(analogRead(A0)); 299 if (valPosition > valControl + 3){ // new position is far 300 if(currentMillis - previousMillis > interval){ 301 previousMillis = currentMillis; 302 // set speed to __ out of possible range 80~255 303 analogWrite(enA, 140); 304 digitalWrite(in1, HIGH); 305 digitalWrite(in2, LOW); 306// delay(200); 307// digitalWrite(in1, LOW); 308 outgoingHeadByte = '<<<'; 309 Serial.write(outgoingHeadByte); 310 Serial.println(""); 311 } 312 } 313 else if(valPosition < valControl - 3){ // new position is far 314 if(currentMillis - previousMillis > interval) { 315 previousMillis = currentMillis; 316 // do Thing B 317 // turn on motor A backward 318 // set speed to __ out of possible range 80~255 319 analogWrite(enA, 140); 320 digitalWrite(in1, LOW); 321 digitalWrite(in2, HIGH); 322// delay(200); 323// digitalWrite(in2, LOW); 324 outgoingHeadByte = '>>>'; 325 Serial.write(outgoingHeadByte); 326 Serial.println(""); 327 } 328 } 329 else if (valPosition == valControl + 2){ // new position is getting close 330 if(currentMillis - previousMillis > interval){ 331 previousMillis = currentMillis; 332 // set speed to __ out of possible range 80~255 333 analogWrite(enA, 100); 334 digitalWrite(in1, HIGH); 335 digitalWrite(in2, LOW); 336// delay(100); 337// digitalWrite(in1, LOW); 338 outgoingHeadByte = '<<'; 339 Serial.write(outgoingHeadByte); 340 Serial.println(""); 341 } 342 } 343 else if(valPosition == valControl - 2){ // new position is getting close 344 if(currentMillis - previousMillis > interval) { 345 previousMillis = currentMillis; 346 // do Thing B 347 // turn on motor A backward 348 // set speed to __ out of possible range 80~255 349 analogWrite(enA, 100); 350 digitalWrite(in1, LOW); 351 digitalWrite(in2, HIGH); 352// delay(100); 353// digitalWrite(in2, LOW); 354 outgoingHeadByte = '>>'; 355 Serial.write(outgoingHeadByte); 356 Serial.println(""); 357 } 358 } 359 else if (valPosition == valControl + 1){ // new position is next over 360 if(currentMillis - previousMillis > interval){ 361 previousMillis = currentMillis; 362 // set speed to __ out of possible range 80~255 363 analogWrite(enA, 85); 364 digitalWrite(in1, HIGH); 365 digitalWrite(in2, LOW); 366// delay(100); 367// digitalWrite(in1, LOW); 368 outgoingHeadByte = '<'; 369 Serial.write(outgoingHeadByte); 370 Serial.println(""); 371 } 372 } 373 else if(valPosition == valControl - 1){ // new position is next over 374 if(currentMillis - previousMillis > interval) { 375 previousMillis = currentMillis; 376 // do Thing B 377 // turn on motor A backward 378 // set speed to __ out of possible range 80~255 379 analogWrite(enA, 85); 380 digitalWrite(in1, LOW); 381 digitalWrite(in2, HIGH); 382// delay(100); 383// digitalWrite(in2, LOW); 384 outgoingHeadByte = '>'; 385 Serial.write(outgoingHeadByte); 386 Serial.println(""); 387 } 388 } 389 else 390 { 391 previousMillis = currentMillis; 392 // do Thing C 393 // turn motor off 394 analogWrite(enA, 0); 395 digitalWrite(in1, LOW); 396 digitalWrite(in2, LOW); 397 outgoingHeadByte = '-'; 398 Serial.write(outgoingHeadByte); 399 Serial.println(""); 400 } 401} 402//---------------------end headTurn-------------------- 403//********************************************************* 404//********************************************************* 405//---------------------begin blink slow------------------- 406void blinkSlow(){ 407unsigned long currentMillis = millis(); 408const long interval1 = 500; 409 410 if(currentMillis - previousMillis >= interval1) { 411 previousMillis = currentMillis; 412 if(ledState == LOW){ 413 ledState = HIGH; 414 } 415 else{ 416 ledState = LOW; 417 } 418 digitalWrite(ledPin, ledState); 419 } 420} 421//---------------------end blink slow------------------- 422//---------------------begin blink fast ------------------- 423void blinkFast(){ 424unsigned long currentMillis = millis(); 425const long interval2 = 75; 426 if(currentMillis - previousMillis >= interval2){ 427 previousMillis = currentMillis; 428 if(ledState == LOW){ 429 ledState = HIGH; 430 } 431 else{ 432 ledState = LOW; 433 } 434 digitalWrite(ledPin, ledState); 435 } 436} 437//---------------------end blink fast ------------------- 438
22102018 graves uno head code
c_cpp
code for arduino uno that controls head movement
1/* 2last edit monday oct 22 2018 3 4gravesunohead 5 6graves project 7arduino Uno 8Slave 1 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17*/ 18 19 20// L298n motor controller code 21// connect motor controller pins to Arduino digital pins 22// motor one 23int enA = 10; 24int in1 = 8; 25int in2 = 9; 26// L298n motor controller code 27 28// pot switches 29//int potControlPin = A1; // analog pin used to connect the controller potentiometer 30//int valControl; // variable to read the value from the analog pin for control input 31//int potControl = 0; // variable to store the servo position from the controller pot switch 32int potPositionPin = A0; // analog pin used to connect the position monitoring potentiometer 33int valPosition; // variable to read the value from the analog pin connected to position monitor 34int potPosition = 0; // variable to store the servo position of the monitoring pot switch 35// pot switches 36int detectedPosition; // variable to store info 37boolean pirStatus; 38 39int servangle = 0; // servo angle variable 40int pirNo[] = {3,4,5,6,7}; // pir pin numbers 41int pirPrevLow[] = {1,1,1,1,1}; // previously low flag set to true 42int pirPrevUsed[] = {0,0,0,0,0}; // has pir been on used before going low 43int pirPos[] = {10,60,100,140,170}; // positions for servo (0-180) 44int curPosPir = 0; 45int pirPin = 3; 46 47 48unsigned long time; 49 50// for blinking 51const int ledPin = LED_BUILTIN;// the number of the LED pin 52int ledState = LOW; // ledState used to set the LED 53unsigned long previousMillis = 0; // will store last time LED was updated 54 55long interval = 1; // interval at which to move servos (milliseconds) 56 57char incomingHeadByte; 58char outgoingHeadByte; 59int headOnOffAdjusted; 60int headOnOffOld; 61int headOnOffNew; 62 63 64void setup() { 65 delay(5000); 66 Serial.begin(9600); 67 incomingHeadByte = 0; // for incoming serial data 68 outgoingHeadByte = 0; // for a bit more talkative serial data 69 headOnOffAdjusted = 1; 70 headOnOffOld = 1; // stores head state from serial connection 71 headOnOffNew = 1; // stores head state from serial connection 72 73 74 time = millis(); 75 // motor control setup code 76 // set all the motor control pins to outputs 77 pinMode(enA, OUTPUT); 78 pinMode(in1, OUTPUT); 79 pinMode(in2, OUTPUT); 80 // motor control setup code 81 pinMode(LED_BUILTIN, OUTPUT); 82 83 // blink led to denote ready 84 blinkSlow(); 85} 86//---------------------end void setup----------------------- 87//---------------------end void setup----------------------- 88//---------------------end void setup----------------------- 89 90//---------------------begin void loop----------------------- 91//---------------------begin void loop----------------------- 92//---------------------begin void loop----------------------- 93 94void loop(){ 95 serialDoStuff(); 96 if(headOnOffNew == headOnOffOld){ 97 if(headOnOffNew == 1){ 98 sensePositionFunction(); 99 headTurn(); 100 } 101 if(headOnOffNew == 2){ 102 } 103 } 104 else if(headOnOffNew != headOnOffOld){ 105 headOnOffNew = headOnOffOld; 106 } 107} 108 109//---------------------end void loop----------------------- 110//---------------------end void loop----------------------- 111//---------------------end void loop----------------------- 112 113 114//********************************************************* 115//********************************************************* 116 117//---------------------begin serialDoStuff ----------------- 118void serialDoStuff(){ 119 if(Serial.available() > 0){ 120 incomingHeadByte = Serial.read(); 121 headOnOffAdjusted = incomingHeadByte - '0'; 122 if(headOnOffAdjusted == 1){ 123 Serial.flush(); 124// outgoingHeadByte = 1; 125// Serial.write(outgoingHeadByte); 126 headOnOffOld = 1; 127 } 128 else if(headOnOffAdjusted == 2){ 129 Serial.flush(); 130// outgoingHeadByte = 2; 131// Serial.write(outgoingHeadByte); 132 headOnOffOld = 2; 133 } 134 } 135} 136//---------------------end serialDoStuff----------------- 137 138//********************************************************* 139//********************************************************* 140//********************************************************* 141//********************************************************* 142// ++++++++++++++++++begin PIR function +++++++++++++++++++++++++++++++ 143void sensePositionFunction(){ 144 for(int j=0;j<5;j++){ // do this for each PIR in the array 145 pirPin=pirNo[j]; 146 pirStatus = digitalRead(pirPin); 147 if(pirStatus == HIGH){ // while cycling through the array if pirNo[j] is HIGH, do this 148 if(pirPrevLow[j]){ // and If pirNo[j] was previously low, do this 149 if(curPosPir != pirPin && pirPrevUsed[j] == 0){ // if pirNo[j] is HIGH and different than curPosPir, move to new position 150 curPosPir = pirPin; // keep current PIR 151 pirPrevUsed[j] = 1; 152 detectedPosition = pirPin; 153// return detectedPosition; 154 } 155 pirPrevLow[j] = 0; // pir is now not low 156 } 157 } 158 else{ 159 pirPrevLow[j] = 1; // pir is now low 160 pirPrevUsed[j] = 0; 161 } 162 } // end j number of pirs loop 163} 164//+++++++++++++++++++++++end PIR function +++++++++++++++++++++++++++++++ 165//********************************************************* 166//********************************************************* 167 168//---------------------begin headTurn ------------------- 169 170void headTurn() { 171 unsigned long currentMillis = millis(); 172 173 // begin potservo section for potentiometer control 174 int valControl = detectedPosition; // reads the value of the potentiometer (value between 0 and 1023) 175 int valPosition = analogRead(potPositionPin); 176 valControl = map(valControl, 0, 1023, 0, 10); // first 0 refers to pot minimum, second is pot maximum, 177 valPosition = map(valPosition, 0, 1023, 0, 10); // third is minimum servo angle, fourth is maximum servo angle 178// Serial.print("control "); 179// Serial.println(valControl); 180// Serial.print(" position "); 181// Serial.println(valPosition); 182 if (valPosition > valControl) 183 { 184 // do Thing A 185 // turn on motor A forward 186 if (currentMillis - previousMillis > interval) { 187 previousMillis = currentMillis; 188 // set speed to __ out of possible range 80~255 189 analogWrite(enA, 100); 190 digitalWrite(in1, HIGH); 191 digitalWrite(in2, LOW); 192 blinkSlow(); 193 outgoingHeadByte = '<'; 194 Serial.write(outgoingHeadByte); 195 } 196 } 197 else if (valPosition < valControl) 198 { 199 if (currentMillis - previousMillis > interval) { 200 previousMillis = currentMillis; 201 // do Thing B 202 // turn on motor A backward 203 // set speed to __ out of possible range 80~255 204 analogWrite(enA, 100); 205 digitalWrite(in1, LOW); 206 digitalWrite(in2, HIGH); 207 blinkFast(); 208 outgoingHeadByte = '>'; 209 Serial.write(outgoingHeadByte); 210 } 211 } 212 else 213 { 214 previousMillis = currentMillis; 215 // do Thing C 216 // turn motor off 217 analogWrite(enA, 0); 218 digitalWrite(in1, LOW); 219 digitalWrite(in2, LOW); 220 } 221} 222//---------------------end headTurn-------------------- 223//********************************************************* 224//********************************************************* 225//---------------------begin blink slow------------------- 226void blinkSlow(){ 227unsigned long currentMillis = millis(); 228const long interval1 = 500; 229 230 if(currentMillis - previousMillis >= interval1) { 231 previousMillis = currentMillis; 232 if(ledState == LOW){ 233 ledState = HIGH; 234 } 235 else{ 236 ledState = LOW; 237 } 238 digitalWrite(ledPin, ledState); 239 } 240} 241//---------------------end blink slow------------------- 242//---------------------begin blink fast ------------------- 243void blinkFast(){ 244unsigned long currentMillis = millis(); 245const long interval2 = 75; 246 if(currentMillis - previousMillis >= interval2){ 247 previousMillis = currentMillis; 248 if(ledState == LOW){ 249 ledState = HIGH; 250 } 251 else{ 252 ledState = LOW; 253 } 254 digitalWrite(ledPin, ledState); 255 } 256} 257//---------------------end blink fast ------------------- 258
do you expect me to talk?
c_cpp
No! I expect you to communicate over simple tx/rx ports like you already know how...even though I don't.
1/* 2last edit monday oct 15 2018 midnight 3working on serial coms 4 5 6gravesmegamaster 7 8graves project 9arduino MEGA 2650 10Master 11coded from scratch by wylie jones 12wyliejones@gmail.com 13 14Graves multi arduino build 10/2018 15Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 16two arduino uno's 17slave1 arduino uno to sense sound from graves and echo dot to control mouth 18slave2 arduino uno to control passive sensor array and head servo 19 20sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 21 22 analogue pin speaker + 23 \ / (red from speaker) 24 \ / 25 \ / 26 *--------[=]-----------*---------[=]----------* 27 | resistor \ resistor | 28 | \ | 29 |(red with white) \ |to arduino ground (black with white) 30to arduino 5v+ speaker - 31 (black from speaker) 32 33*/ 34//end notes 35//end notes 36//end notes 37//end notes 38//end notes 39//end notes 40 41 42//********************************************************* 43//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 44//********************************************************* 45 46 47//begin declarations 48//begin declarations 49//begin declarations 50//begin declarations 51//begin declarations 52//begin declarations 53//begin declarations 54 55//#include <TFT.h> 56//#include <Servo.h> 57//#include <stdint.h> 58//#include <SD.h> 59#include <TFTv2.h> 60#include <SPI.h> 61#include <SeeedTouchScreen.h> 62#include <Wire.h> 63 64//const int PIN_SD_CS = 4; // pin of sd card 65 66TouchScreen ts = TouchScreen(XP, YP, XM, YM); 67int zMax; // maximum pressure to detect 68int zMin; // minimum pressure to detect 69 70int buttonPressed; // stores which button was pressed 71unsigned long newButtonTime; // debounce 72unsigned long oldButtonTime; // debounce 73unsigned long buttonTimeDifference; // debounce 74unsigned long debounceTime; // debounce 75int buttonGroup; // sets kinds of buttons on screen 76 77int currentScreen; // identifies current screen by adding x y and z 78int x; // for ones 79int y; // for tens 80int z; // for hundreds 81 82unsigned long backlightTimer; // for backlight timeout 83int backLightState; // status of backlight 1 for on and 0 for off 84unsigned long backlightTimeDifference; 85unsigned long newBacklightTime; 86unsigned long oldBacklightTime; 87 88int incomingMouthByte; 89int outgoingMouthByte; 90int mouthOnOff; 91 92int incomingHeadByte; 93int outgoingHeadByte; 94int headOnOff; 95 96//end declarations 97//end declarations 98//end declarations 99//end declarations 100//end declarations 101//end declarations 102//end declarations 103//end declarations 104//end declarations 105 106//********************************************************* 107//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 108//********************************************************* 109 110// begin void setup 111// begin void setup 112// begin void setup 113// begin void setup 114// begin void setup 115// begin void setup 116// begin void setup 117// begin void setup 118// begin void setup 119// begin void setup 120// begin void setup 121void setup() { 122Serial.begin(9600); 123 oldButtonTime = millis(); 124 newButtonTime = millis(); 125 Tft.TFTinit(); // init TFT library 126 TFT_BL_ON; // turn on the background light 127 backLightState = 1; 128 x = 0; 129 y = 0; 130 z = 0; 131 buttonPressed = 4; 132 buttonGroup = 0; 133 incomingHeadByte = 0; 134 incomingMouthByte = 0; 135 136 //////////////////////////////// 137 //// manually set variables //// 138 //////////////////////////////// 139 140 debounceTime = 1000; // button debounce in milliseconds 141 zMax = 460; // maximum pressure to detect 142 zMin = 100; // minimum pressure to detect 143 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 144 145 146 currentScreen = 0; 147 callScreen(); 148 149} //void setup() 150// end void setup 151// end void setup 152// end void setup 153// end void setup 154// end void setup 155// end void setup 156// end void setup 157// end void setup 158 159//********************************************************* 160//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 161//********************************************************* 162 163// begin void loop 164// begin void loop 165// begin void loop 166// begin void loop 167// begin void loop 168// begin void loop 169// begin void loop 170// begin void loop 171// begin void loop 172// begin void loop 173// begin void loop 174// begin void loop 175// begin void loop 176// begin void loop 177 178void loop() { 179 180 tftBacklightTimeout(); // check time and turn off backlight 181 182 if(buttonGroup == 0){ // most regular pages 183 tftButtonGroup0(); // gather information from touch screen touches 184 buttonTimeDifference = newButtonTime - oldButtonTime; 185 if(debounceTime < buttonTimeDifference){ 186 whatScreen(); 187 callScreen(); 188 oldButtonTime = newButtonTime; 189 showStuff(); // serial prints 190 tftDisplay(); // display x y coordinates on tft display 191 } 192 } 193 if(buttonGroup == 1){ // on off buttons 194 tftButtonGroup1(); // gather information from touch screen touches 195 buttonTimeDifference = newButtonTime - oldButtonTime; 196 if(debounceTime < buttonTimeDifference){ 197 whatScreen(); 198 callScreen(); 199 oldButtonTime = newButtonTime; 200 showStuff(); // serial prints 201 tftDisplay(); // display x y coordinates on tft display 202 mouthUnoTxRx(); 203 } 204 } 205 if(buttonGroup == 2){ // head buttons 206 tftButtonGroup2(); // gather information from touch screen touches 207 buttonTimeDifference = newButtonTime - oldButtonTime; 208 if(debounceTime < buttonTimeDifference){ 209 whatScreen(); 210 callScreen(); 211 oldButtonTime = newButtonTime; 212 showStuff(); // serial prints 213 tftDisplay(); // display x y coordinates on tft display 214 } 215 } 216 217 218} //void loop() 219 220// end of void loop 221// end of void loop 222// end of void loop 223// end of void loop 224// end of void loop 225// end of void loop 226// end of void loop 227// end of void loop 228// end of void loop 229// end of void loop 230// end of void loop 231// end of void loop 232// end of void loop 233// end of void loop 234// end of void loop 235 236//**************************************************************************************************** 237//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 238//**************************************************************************************************** 239///////////////////////////////////////////////////////////////////////////////////////////////////////// 240///////////////////////////////////////// functions /////////////////////////////////////////////////// 241///////////////////////////////////////////////////////////////////////////////////////////////////////// 242//**************************************************************************************************** 243//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 244//**************************************************************************************************** 245 246//--------------------------begin tftBacklightTimeout---------------------------------- 247void tftBacklightTimeout(){ 248 newBacklightTime = millis(); 249 if(backLightState = 0){ 250 backlightTimeDifference = newBacklightTime - oldBacklightTime; 251 if(backlightTimer > backlightTimeDifference){ 252 backlightTimeDifference = newBacklightTime - oldBacklightTime; 253 TFT_BL_ON; // turn on the background light 254 backLightState = 1; 255 oldBacklightTime = millis(); 256 } 257 } 258 if(backLightState = 1){ 259 backlightTimeDifference = newBacklightTime - oldBacklightTime; 260 if(backlightTimer < backlightTimeDifference){ 261 backlightTimeDifference = newBacklightTime - oldBacklightTime; 262 TFT_BL_OFF; // turn off the background light 263 backLightState = 0; 264 oldBacklightTime = millis(); 265 } 266 } 267} 268//--------------------------end tftBacklightTimeout---------------------------------- 269 270//**************************************************************************************************** 271//**************************************************************************************************** 272 273//--------------------------begin tftButtonGroup0---------------------------------- 274//--------------------------begin tftButtonGroup0---------------------------------- 275//--------------------------begin tftButtonGroup0---------------------------------- 276//--------------------------begin tftButtonGroup0---------------------------------- 277int tftButtonGroup0(){ 278 Point p = ts.getPoint(); 279 if(zMin<p.z && p.z<zMax){ 280 TFT_BL_ON; // turn on the background light 281 backLightState = 1; 282 oldBacklightTime = millis(); 283 newButtonTime = millis(); 284 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 285 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 286//Button 1 287 if(75<p.x && p.x<140){ 288 if(100<p.y && p.y<164){ 289 buttonPressed = 1; 290 } 291//Button 2 292 if(164<p.y && p.y<240){ 293 buttonPressed = 2; 294 } 295//Button 3 296 if(240<p.y && p.y<310){ 297 buttonPressed = 3; 298 } 299 } 300 } 301//Button 4 302 if(10<p.x && p.x<75){ 303 if(100<p.y && p.y<240){ 304 buttonPressed = 4; 305 } 306 } 307}//void tftButtonGroup0 308//--------------------------end tftButtonGroup0 code---------------------------------- 309//--------------------------end tftButtonGroup0 code---------------------------------- 310//--------------------------end tftButtonGroup0 code---------------------------------- 311//--------------------------end tftButtonGroup0 code---------------------------------- 312//--------------------------end tftButtonGroup0 code---------------------------------- 313//**************************************************************************************************** 314//**************************************************************************************************** 315 316//--------------------------begin tftButtonGroup1---------------------------------- 317//--------------------------begin tftButtonGroup1---------------------------------- 318//--------------------------begin tftButtonGroup1---------------------------------- 319//--------------------------begin tftButtonGroup1---------------------------------- 320int tftButtonGroup1(){ // for mouth 321buttonPressed = 0; 322 Point p = ts.getPoint(); 323 if(zMin<p.z && p.z<zMax){ 324 TFT_BL_ON; // turn on the background light 325 backLightState = 1; 326 oldBacklightTime = millis(); 327 newButtonTime = millis(); 328 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 329 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 330//Button 1 331 if(75<p.x && p.x<140){ 332 if(100<p.y && p.y<164){ 333 mouthOnOff = 1; // on 334 Serial.print("mouthOnOff set to "); 335 Serial.println(mouthOnOff); 336 } 337//Button 2 338 if(164<p.y && p.y<240){ 339 mouthOnOff = 0; // off 340 Serial.print("mouthOnOff set to "); 341 Serial.println(mouthOnOff); 342 } 343//Button 3 344// if(240<p.y && p.y<310){ 345// buttonPressed = 3; 346// } 347 } 348 } 349//Button 4 350 if(10<p.x && p.x<75){ 351 if(100<p.y && p.y<240){ 352 buttonPressed = 4; 353 buttonGroup = 0; 354 } 355 } 356}//void tftButtonGroup1 357//--------------------------end tftButtonGroup1 code---------------------------------- 358//--------------------------end tftButtonGroup1 code---------------------------------- 359//--------------------------end tftButtonGroup1 code---------------------------------- 360//--------------------------end tftButtonGroup1 code---------------------------------- 361//--------------------------end tftButtonGroup1 code---------------------------------- 362//**************************************************************************************************** 363//**************************************************************************************************** 364 365//--------------------------begin tftButtonGroup2---------------------------------- 366//--------------------------begin tftButtonGroup2---------------------------------- 367//--------------------------begin tftButtonGroup2---------------------------------- 368//--------------------------begin tftButtonGroup2---------------------------------- 369int tftButtonGroup2(){ // for head 370buttonPressed = 0; 371 Point p = ts.getPoint(); 372 if(zMin<p.z && p.z<zMax){ 373 TFT_BL_ON; // turn on the background light 374 backLightState = 1; 375 oldBacklightTime = millis(); 376 newButtonTime = millis(); 377 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 378 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 379//Button 1 380 if(75<p.x && p.x<140){ 381 if(100<p.y && p.y<164){ 382 headOnOff = 1; // on 383 } 384//Button 2 385 if(164<p.y && p.y<240){ 386 headOnOff = 0; // off 387 } 388//Button 3 389// if(240<p.y && p.y<310){ 390// buttonPressed = 3; 391// } 392 } 393 } 394//Button 4 395 if(10<p.x && p.x<75){ 396 if(100<p.y && p.y<240){ 397 buttonPressed = 4; 398 buttonGroup = 0; 399 } 400 } 401}//void tftButtonGroup2 402//--------------------------end tftButtonGroup2 code---------------------------------- 403//--------------------------end tftButtonGroup2 code---------------------------------- 404//--------------------------end tftButtonGroup2 code---------------------------------- 405//--------------------------end tftButtonGroup2 code---------------------------------- 406//--------------------------end tftButtonGroup2 code---------------------------------- 407//**************************************************************************************************** 408//**************************************************************************************************** 409//-------------------------- begin whatScreen function ------------------------- 410//-------------------------- begin whatScreen function ------------------------- 411//-------------------------- begin whatScreen function ------------------------- 412//-------------------------- begin whatScreen function ------------------------- 413 414int whatScreen(){ 415 if(x == 0){ 416 if(buttonPressed == 1){ 417 x = x + 1; 418 Serial.println("x + 1"); 419 } 420 if(buttonPressed == 2){ 421 x = x + 2; 422 Serial.println("x + 2"); 423 } 424 if(buttonPressed == 3){ 425 x = x + 3; 426 Serial.println("x + 3"); 427 } 428 if(buttonPressed == 4){ 429 x = 0; 430 Serial.println("x = 0"); 431 } 432 if(buttonPressed == 5){ 433 x = 0; 434 y = 0; 435 z = 0; 436 Serial.println("xyz all 0"); 437 } 438 } 439 else if(x >> 0){ 440 if(y == 0){ 441 if(buttonPressed == 1){ 442 y = y + 10; 443 Serial.println("y + 10"); 444 } 445 if(buttonPressed == 2){ 446 y = y + 20; 447 Serial.println("y + 20"); 448 } 449 if(buttonPressed == 3){ 450 y = y + 30; 451 Serial.println("y + 30"); 452 } 453 if(buttonPressed == 4){ 454 x = 0; 455 Serial.println("x = 0"); 456 } 457 if(buttonPressed == 5){ 458 x = 0; 459 y = 0; 460 z = 0; 461 Serial.println("xyz all 0"); 462 } 463 } 464 else if (y >> 0){ 465 if(buttonPressed == 1){ 466 z = z + 100; 467 Serial.println("z + 100"); 468 } 469 if(buttonPressed == 2){ 470 z = z + 200; 471 Serial.println("z + 200"); 472 } 473 if(buttonPressed == 3){ 474 z = z + 300; 475 Serial.println("z + 300"); 476 } 477 if(buttonPressed == 4){ 478 if(z == 0){ 479 y = 0; 480 Serial.println("y = 0"); 481 } 482 else if(z >> 0){ 483 z = 0; 484 Serial.println("z = 0"); 485 } 486 } 487 if(buttonPressed == 5){ 488 x = 0; 489 y = 0; 490 z = 0; 491 Serial.println("xyz all 0"); 492 } 493 }//y>0 494 }//x>0 495 currentScreen = z+y+x; 496 if(currentScreen == 122){ 497 buttonGroup=1; 498 } 499 if(currentScreen == 222){ 500 buttonGroup=1; 501 } 502 if(currentScreen == 23){ 503 buttonGroup=2; 504 } 505} 506//-------------------------- end whatScreen function ------------------------- 507//-------------------------- end whatScreen function ------------------------- 508//-------------------------- end whatScreen function ------------------------- 509//-------------------------- end whatScreen function ------------------------- 510//-------------------------- end whatScreen function ------------------------- 511 512//**************************************************************************************************** 513//**************************************************************************************************** 514 515//--------------------------begin mouthUnoTxRx---------------------------------- 516 517void mouthUnoTxRx(){ 518 outgoingMouthByte = mouthOnOff; 519 if(Serial1){ 520 Serial1.println(outgoingMouthByte); // send to serial connection 521// incomingMouthByte = Serial1.read(); // read the incoming byte: 522 Serial.print("uno mouth wrote: "); 523 Serial.println(outgoingMouthByte); 524 } 525} 526 527//--------------------------end mouthUnoTxRx -------------------------------------- 528//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 529//--------------------------begin headUnoTxRx -------------------------------------- 530 531// call slave1 arduino for data 532 533void headUnoTxRx(){ 534 outgoingHeadByte = headOnOff; 535 if(Serial2){ 536 Serial2.println(outgoingHeadByte); // send to serial connection 537 incomingHeadByte = Serial2.read(); // read the incoming byte: 538 Serial.print("uno head received and wrote: "); 539 Serial.println(incomingHeadByte, DEC); 540 } 541} 542 543// call slave2 arduino for data 544//--------------------------end headUnoTxRx -------------------------------------- 545 546//**************************************************************************************************** 547//**************************************************************************************************** 548 549//--------------------------begin tftDisplay code---------------------------------- 550void tftDisplay(){ 551 Point p = ts.getPoint(); 552 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 553 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 554 Tft.fillRectangle(0, 225, 60, 30, BLACK); 555 Tft.drawNumber((p.x), 0, 225, 3, GREEN); 556 Tft.fillRectangle(180, 225, 60, 30, BLACK); 557 Tft.drawNumber((p.y), 180, 225, 3, GREEN); 558 Tft.fillRectangle(100, 225, 60, 30, BLACK); 559 Tft.drawNumber((buttonPressed), 100, 225, 3, GREEN); 560 Tft.fillRectangle(70, 160, 60, 30, BLACK); 561 Tft.drawNumber((mouthOnOff), 70, 160, 3, GREEN); 562 Tft.fillRectangle(140, 160, 60, 30, BLACK); 563 Tft.drawNumber((headOnOff), 140, 160, 3, GREEN); 564 Tft.fillRectangle(120, 290, 60, 30, BLACK); 565 Tft.drawNumber((currentScreen), 120, 290, 3, GREEN); 566 567 568}// void tftDisplay 569//--------------------------end tftDisplay code------------------------------------ 570 571//**************************************************************************************************** 572//**************************************************************************************************** 573 574//-------------------------- begin mouth on off function -------------------------- 575//-------------------------- end mouth on off function -------------------------- 576 577//**************************************************************************************************** 578//**************************************************************************************************** 579 580//-------------------------- begin head on off function -------------------------- 581//-------------------------- end head on off function ------------------------- 582 583//**************************************************************************************************** 584//**************************************************************************************************** 585 586//-------------------------- begin serial display function -------------------------- 587void showStuff(){ 588 Serial.println("------/ last update /-------"); 589// Serial.println("------begin display-------"); 590 Serial.print("buttonPressed "); 591 Serial.println(buttonPressed); 592 Serial.print("x "); 593 Serial.println(x); 594 Serial.print("y "); 595 Serial.println(y); 596 Serial.print("z "); 597 Serial.println(z); 598 Serial.print("currentScreen "); 599 Serial.println(currentScreen); 600// Serial.println("-------end display--------"); 601 Serial.println(""); 602 Serial.println(""); 603 Serial.println(""); 604 } 605//-------------------------- end serial display function ------------------------- 606 607 608//**************************************************************************************************** 609//**************************************************************************************************** 610 611//--------------------------- Primary screen maps -------------------------------- 612/* 613******** 614updates needed 615******** 6161 ditch the contrast 6172 ditch the brightness 6183 setup screen timeout 619 620 621 622 623screen 0000 A)Home 624 screen 0001 a)settings 625 screen 0011 -brightness 626 screen 0011 -contrast 627 screen 0011 -screen lock time out 628 screen 0001 b)sensor monitors 629 screen 0021 -pir 630 screen 0121 *report pir detection 631 screen 0021 -sound 632 screen 0221 *sense alexa sound 633 screen 0221 *sense graves sound 634 screen 0221 *report mouth servo position 635 screen 0221 *adjust sensitivity? 636 screen 0021 -head potentiometer 637 screen 0021 -bluetooth 638 screen 0001 c)bluetooth 639 screen 0031 -on 640 screen 0031 -off 641 screen 0031 -monitor 642screen 0000 B)Mouth Control 643 screen 0002 a)test button 644 screen 0012 -open 645 screen 0012 -close 646 screen 0012 -push button chicken switch 647 screen 0002 b)sound sensors on/off 648 screen 0022 -alexa sense 649 screen 0122 *on 650 screen 0122 *off 651 screen 0122 *monitor sensor 652 screen 0022 -graves sense 653 screen 0222 *on 654 screen 0222 *off 655 screen 0222 *monitor sensors 656 screen 0002 c)sound sensor status 657 screen 0032 -alexa 658 screen 0032 -graves 659screen 0000 C)Head Control 660 screen 0003 a)pir on/off 661 screen 0013 -on 662 screen 0013 -off 663 screen 0013 -sensor 664 screen 0003 b)manual point 665 screen 0023 -slider 666*/ 667//**************************************************************************************************** 668//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 669//**************************************************************************************************** 670//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 671//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 672//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 673//**************************************************************************************************** 674//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 675//**************************************************************************************************** 676 677//-------------------------- begin callScreen function ------------------------- 678//-------------------------- begin callScreen function ------------------------- 679//-------------------------- begin callScreen function ------------------------- 680//-------------------------- begin callScreen function ------------------------- 681//-------------------------- begin callScreen function ------------------------- 682//-------------------------- begin callScreen function ------------------------- 683//-------------------------- begin callScreen function ------------------------- 684//-------------------------- begin callScreen function ------------------------- 685//-------------------------- begin callScreen function ------------------------- 686//-------------------------- begin callScreen function ------------------------- 687//-------------------------- begin callScreen function ------------------------- 688 689int callScreen(){ 690 Tft.fillRectangle(0, 0, 240, 320, BLACK); 691 692//<><><><><><><><><><><><><><><><><><><><><><><><> 693//<><><><><><><><> begin screen 0000 master <><><><><><><><> 694//<><><><><><><><><><><><><><><><><><><><><><><><> 695if(currentScreen == 0){ 696 // " " 697 Tft.drawString("GRAVES",0,5,4, GREEN); 698 Tft.drawString("INTERFACE",10,50,4,GREEN); 699 Tft.drawString("Home", 80,130, 3, GREEN); 700 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 701 Tft.drawString("Head Control", 10, 260, 3, GREEN); 702} 703//<><><><><><><><><><><><><><><><><><><><><><><><> 704//<><><><><><><><> end screen 0000 master <><><><><><><><><> 705//<><><><><><><><><><><><><><><><><><><><><><><><> 706 707//<><><><><><><><><><><><><><><><><><><><><><><><> 708//<><><><><><><><> begin screen 0001 <><><><><><><><> 709//<><><><><><><><><><><><><><><><><><><><><><><><> 710 if(currentScreen == 1){ 711 // " " 712 Tft.drawString("MEGA 2560",00,5,4,BLUE); 713 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 714 Tft.drawString("Settings", 10,130, 3, BLUE); 715 Tft.drawString("Sensors", 20, 195, 3, BLUE); 716 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 717 Tft.drawString("<", 0, 160, 3, GREEN); // back button 718} 719//<><><><><><><><><><><><><><><><><><><><><><><><> 720//<><><><><><><><> end screen 0001 <><><><><><><><><> 721//<><><><><><><><><><><><><><><><><><><><><><><><> 722 723//<><><><><><><><><><><><><><><><><><><><><><><><> 724//<><><><><><><><> begin screen 0011 <><><><><><><><> 725//<><><><><><><><><><><><><><><><><><><><><><><><> 726 if(currentScreen == 11){ 727 // " " 728 Tft.drawString("MEGA 2560",00,5,4,BLUE); 729 Tft.drawString("SETTINGS",10,50,4,YELLOW); 730 Tft.drawString("Brightness", 80,130, 3, BLUE); 731 Tft.drawString("Contrast", 05, 195, 3, GREEN); 732 Tft.drawString("Timeout", 10, 260, 3, GREEN); 733 Tft.drawString("<", 0, 160, 3, GREEN); // back button 734} 735 736//<><><><><><><><><><><><><><><><><><><><><><><><> 737//<><><><><><><><> end screen 0011 <><><><><><><><><> 738//<><><><><><><><><><><><><><><><><><><><><><><><> 739 740//<><><><><><><><><><><><><><><><><><><><><><><><> 741//<><><><><><><><> begin screen 0021 <><><><><><><><> 742//<><><><><><><><><><><><><><><><><><><><><><><><> 743 if(currentScreen == 21){ 744 // " " 745 Tft.drawString("MEGA 2560",00,5,4,BLUE); 746 Tft.drawString("SENSORS",10,50,4,YELLOW); 747 Tft.drawString("PIR Array", 80,130, 3, BLUE); 748 Tft.drawString("Sound", 05, 195, 3, GREEN); 749 Tft.drawString("Head Position", 10, 260, 3, GREEN); 750 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 751 Tft.drawString("<", 0, 160, 3, GREEN); // back button 752} 753//<><><><><><><><><><><><><><><><><><><><><><><><> 754//<><><><><><><><> end screen 0021 <><><><><><><><><> 755//<><><><><><><><><><><><><><><><><><><><><><><><> 756 757//<><><><><><><><><><><><><><><><><><><><><><><><> 758//<><><><><><><><> begin screen 0121 <><><><><><><><> 759//<><><><><><><><><><><><><><><><><><><><><><><><> 760 if(currentScreen == 121){ 761 // " " 762 Tft.drawString("PIR",0,5,4,BLUE); 763 Tft.drawString("ARRAY",10,50,4,YELLOW); 764 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 765 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 766 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 767 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 768 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 769 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 770 Tft.drawString("<", 0, 160, 3, GREEN); // back button 771} 772//<><><><><><><><><><><><><><><><><><><><><><><><> 773//<><><><><><><><> end screen 0121 <><><><><><><><><> 774//<><><><><><><><><><><><><><><><><><><><><><><><> 775 776//<><><><><><><><><><><><><><><><><><><><><><><><> 777//<><><><><><><><> begin screen 0221 <><><><><><><><> 778//<><><><><><><><><><><><><><><><><><><><><><><><> 779 if(currentScreen == 221){ 780 // " " 781 Tft.drawString("SOUND",0,5,4,BLUE); 782 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 783 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 784 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 785 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 786 Tft.drawString("<", 0, 160, 3, GREEN); // back button 787} 788//<><><><><><><><><><><><><><><><><><><><><><><><> 789//<><><><><><><><> end screen 0221 <><><><><><><><><> 790//<><><><><><><><><><><><><><><><><><><><><><><><> 791 792//<><><><><><><><><><><><><><><><><><><><><><><><> 793//<><><><><><><><> begin screen 0031 <><><><><><><><> 794//<><><><><><><><><><><><><><><><><><><><><><><><> 795 if(currentScreen == 31){ 796 // " " 797 Tft.drawString("Bluetooth",0,5,4,BLUE); 798 Tft.drawString("Control",10,50,4,YELLOW); 799 Tft.drawString("On", 80,130, 3, BLUE); 800 Tft.drawString("Off", 05, 195, 3, GREEN); 801 Tft.drawString("Monitor", 10, 260, 3, GREEN); 802 Tft.drawString("<", 0, 160, 3, GREEN); // back button 803} 804//<><><><><><><><><><><><><><><><><><><><><><><><> 805//<><><><><><><><> end screen 0031 <><><><><><><><><> 806//<><><><><><><><><><><><><><><><><><><><><><><><> 807 808//<><><><><><><><><><><><><><><><><><><><><><><><> 809//<><><><><><><><> begin screen 0002 <><><><><><><><> 810//<><><><><><><><><><><><><><><><><><><><><><><><> 811 if(currentScreen == 2){ 812 // " " 813 Tft.drawString("Mouth",0,5,4,BLUE); 814 Tft.drawString("Control",10,50,4,YELLOW); 815 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 816 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 817 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 818 Tft.drawString("<", 0, 160, 3, GREEN); // back button 819 } 820//<><><><><><><><><><><><><><><><><><><><><><><><> 821//<><><><><><><><> end screen 0002 <><><><><><><><><> 822//<><><><><><><><><><><><><><><><><><><><><><><><> 823 824 825//<><><><><><><><><><><><><><><><><><><><><><><><> 826//<><><><><><><><> begin screen 0012 <><><><><><><><> 827//<><><><><><><><><><><><><><><><><><><><><><><><> 828 if(currentScreen == 12){ 829 // " " 830 Tft.drawString("Jaw Test",0,5,4,BLUE); 831 Tft.drawString("Operations",10,50,4,YELLOW); 832 Tft.drawString("Open", 80,130, 3, BLUE); 833 Tft.drawString("Close", 05, 195, 3, GREEN); 834 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 835 Tft.drawString("<", 0, 160, 3, GREEN); // back button 836} 837//<><><><><><><><><><><><><><><><><><><><><><><><> 838//<><><><><><><><> end screen 0012 <><><><><><><><><> 839//<><><><><><><><><><><><><><><><><><><><><><><><> 840 841 842//<><><><><><><><><><><><><><><><><><><><><><><><> 843//<><><><><><><><> begin screen 0022 <><><><><><><><> 844//<><><><><><><><><><><><><><><><><><><><><><><><> 845 if(currentScreen == 22){ 846 // " " 847 Tft.drawString("Sound",0,5,4,BLUE); 848 Tft.drawString("Sensors",10,50,4,YELLOW); 849 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 850 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 851 Tft.drawString("Monitor", 10, 260, 3, GREEN); 852 Tft.drawString("<", 0, 160, 3, GREEN); // back button 853} 854//<><><><><><><><><><><><><><><><><><><><><><><><> 855//<><><><><><><><> end screen 0022 <><><><><><><><><> 856//<><><><><><><><><><><><><><><><><><><><><><><><> 857 858 859 860//<><><><><><><><><><><><><><><><><><><><><><><><> 861//<><><><><><><><> begin screen 0122 <><><><><><><><> 862//<><><><><><><><><><><><><><><><><><><><><><><><> 863 if(currentScreen == 122){ 864 // " " 865 Tft.drawString("Alexa Sense",0,5,4,BLUE); 866 Tft.drawString("Operations",10,50,4,YELLOW); 867 Tft.drawString("On", 120, 130, 3, GREEN); 868 Tft.drawString("Off", 115, 195, 3, RED); 869 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 870 Tft.drawString("<", 0, 160, 3, GREEN); // back button 871} 872//<><><><><><><><><><><><><><><><><><><><><><><><> 873//<><><><><><><><> end screen 0122 <><><><><><><><><> 874//<><><><><><><><><><><><><><><><><><><><><><><><> 875 876//<><><><><><><><><><><><><><><><><><><><><><><><> 877//<><><><><><><><> begin screen 0222 <><><><><><><><> 878//<><><><><><><><><><><><><><><><><><><><><><><><> 879 if(currentScreen == 222){ 880 // " " 881 Tft.drawString("Graves Sense",0,5,4,BLUE); 882 Tft.drawString("Operations",10,50,4,YELLOW); 883 Tft.drawString("On", 120, 130, 3, GREEN); 884 Tft.drawString("Off", 115, 195, 3, RED); 885 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 886 Tft.drawString("<", 0, 160, 3, GREEN); // back button 887} 888//<><><><><><><><><><><><><><><><><><><><><><><><> 889//<><><><><><><><> end screen 0222 <><><><><><><><><> 890//<><><><><><><><><><><><><><><><><><><><><><><><> 891 892//<><><><><><><><><><><><><><><><><><><><><><><><> 893//<><><><><><><><> begin screen 0032 <><><><><><><><> 894//<><><><><><><><><><><><><><><><><><><><><><><><> 895 if(currentScreen == 32){ 896 // " " 897 Tft.drawString("Sound Sense",0,5,4,BLUE); 898 Tft.drawString("Monitors",10,50,4,YELLOW); 899 Tft.drawString("Alexa", 80,130, 3, BLUE); 900 Tft.drawString("Graves", 05, 195, 3, GREEN); 901 Tft.drawString("<", 0, 160, 3, GREEN); // back button 902} 903//<><><><><><><><><><><><><><><><><><><><><><><><> 904//<><><><><><><><> end screen 0032 <><><><><><><><><> 905//<><><><><><><><><><><><><><><><><><><><><><><><> 906 907//<><><><><><><><><><><><><><><><><><><><><><><><> 908//<><><><><><><><> begin screen 0003 <><><><><><><><> 909//<><><><><><><><><><><><><><><><><><><><><><><><> 910 if(currentScreen == 3){ 911 // " " 912 Tft.drawString("Head Control",0,5,4,BLUE); 913 Tft.drawString("Operations",10,50,4,YELLOW); 914 Tft.drawString("PIR Array", 80,130, 3, BLUE); 915 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 916 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 917 Tft.drawString("<", 0, 160, 3, GREEN); // back button 918} 919//<><><><><><><><><><><><><><><><><><><><><><><><> 920//<><><><><><><><> end screen 0003 <><><><><><><><><> 921//<><><><><><><><><><><><><><><><><><><><><><><><> 922 923//<><><><><><><><><><><><><><><><><><><><><><><><> 924//<><><><><><><><> begin screen 0013 <><><><><><><><> 925//<><><><><><><><><><><><><><><><><><><><><><><><> 926 if(currentScreen == 13){ 927 // " " 928 Tft.drawString("PIR Control",0,5,4,BLUE); 929 Tft.drawString("Operations",10,50,4,YELLOW); 930 Tft.drawString("On", 80,130, 3, BLUE); 931 Tft.drawString("Off", 05, 195, 3, GREEN); 932 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 933 Tft.drawString("<", 0, 160, 3, GREEN); // back button 934} 935//<><><><><><><><><><><><><><><><><><><><><><><><> 936//<><><><><><><><> end screen 0013 <><><><><><><><><> 937//<><><><><><><><><><><><><><><><><><><><><><><><> 938 939//<><><><><><><><><><><><><><><><><><><><><><><><> 940//<><><><><><><><> begin screen 0023 <><><><><><><><> 941//<><><><><><><><><><><><><><><><><><><><><><><><> 942 if(currentScreen == 23){ 943 // " " 944 Tft.drawString("Graves Head",0,5,3,BLUE); 945 Tft.drawString("Operations",10,50,3,YELLOW); 946 Tft.drawString("On", 120, 130, 3, GREEN); 947 Tft.drawString("Off", 115, 195, 3, RED); 948// Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 949 Tft.drawString("<", 0, 160, 3, GREEN); // back button 950} 951//<><><><><><><><><><><><><><><><><><><><><><><><> 952//<><><><><><><><> end screen 0023 <><><><><><><><><> 953//<><><><><><><><><><><><><><><><><><><><><><><><> 954 955 956//<><><><><><><><><><><><><><><><><><><><><><><><> 957//<><><><><><><><> begin screen 0422 <><><><><><><><> 958//<><><><><><><><><><><><><><><><><><><><><><><><> 959 if(currentScreen == 422){ 960 // " " 961 Tft.drawString("Command Sent",0,5,3,BLUE); 962 Tft.drawString("Press Back to",0,55,3,YELLOW); 963 Tft.drawString("Contiue", 50,105, 3, BLUE); 964 Tft.drawString("<", 0, 160, 3, GREEN); // back button 965} 966//<><><><><><><><><><><><><><><><><><><><><><><><> 967//<><><><><><><><> end screen 0422 <><><><><><><><><> 968//<><><><><><><><><><><><><><><><><><><><><><><><> 969 970 971////<><><><><><><><><><><><><><><><><><><><><><><><> 972////<><><><><><><><> begin screen lost <><><><><><><><> 973////<><><><><><><><><><><><><><><><><><><><><><><><> 974// else if(currentScreen){ 975// // " " 976// Tft.drawString("Screen not",0,5,3,BLUE); 977// Tft.drawString("found. Please",40,50,3,YELLOW); 978// Tft.drawString("use the back", 80,130, 3, BLUE); 979// Tft.drawString("button to", 05, 195, 3, GREEN); 980// Tft.drawString("return to fun", 10, 260, 3, GREEN); 981// Tft.drawString("<", 0, 160, 3, GREEN); // back button 982//} 983////<><><><><><><><><><><><><><><><><><><><><><><><> 984////<><><><><><><><> end screen lost <><><><><><><><><> 985////<><><><><><><><><><><><><><><><><><><><><><><><> 986 987}// callScreen 988//-------------------------- end callScreen function ------------------------- 989//-------------------------- end callScreen function ------------------------- 990//-------------------------- end callScreen function ------------------------- 991//-------------------------- end callScreen function ------------------------- 992//-------------------------- end callScreen function ------------------------- 993//-------------------------- end callScreen function ------------------------- 994//-------------------------- end callScreen function ------------------------- 995//-------------------------- end callScreen function ------------------------- 996//-------------------------- end callScreen function ------------------------- 997//-------------------------- end callScreen function ------------------------- 998//-------------------------- end callScreen function ------------------------- 999//-------------------------- end callScreen function ------------------------- 1000//-------------------------- end callScreen function ------------------------- 1001 1002 1003//**************************************************************************************************** 1004//**************************************************************************************************** 1005 1006 1007 1008 1009 1010 1011 1012//**************************************************************************************************** 1013//**************************************************************************************************** 1014 1015// fin
12102018 later in the day
c_cpp
updated code again. this time with a back light time out. can't figure out why the screen paging program is failing after a minute or two while the back light timer continues. gonna post the code and ask for help.
1/* 2last edit sun oct 12 2018 later in the day 3coded from scratch by wylie jones 4wyliejones@gmail.com 5 6Graves multi arduino build 10/2018 7Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 8two arduino uno's 9slave1 arduino uno to sense sound from graves and echo dot to control mouth 10slave2 arduino uno to control passive sensor array and head servo 11 12sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 13 14 analogue pin speaker + 15 \ / (red from speaker) 16 \ / 17 \ / 18 *--------[=]-----------*---------[=]----------* 19 | resistor \ resistor | 20 | \ | 21 |(red with white) \ |to arduino ground (black with white) 22to arduino 5v+ speaker - 23 (black from speaker) 24 25*/ 26//end notes 27//end notes 28//end notes 29//end notes 30//end notes 31//end notes 32 33 34//********************************************************* 35//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 36//********************************************************* 37 38 39//begin declarations 40//begin declarations 41//begin declarations 42//begin declarations 43//begin declarations 44//begin declarations 45//begin declarations 46 47//#include <TFT.h> 48//#include <Servo.h> 49//#include <stdint.h> 50//#include <SD.h> 51#include <TFTv2.h> 52#include <SPI.h> 53#include <SeeedTouchScreen.h> 54 55//const int PIN_SD_CS = 4; // pin of sd card 56 57TouchScreen ts = TouchScreen(XP, YP, XM, YM); 58int buttonPressed; // stores which button was pressed 59int newButtonTime; // debounce 60int oldButtonTime; // debounce 61int buttonTimeDifference; // debounce 62int debounceTime; // debounce 63int currentScreen; // identifies current screen by adding x y and z 64int x; // for ones 65int y; // for tens 66int z; // for hundreds 67 68int zMax; // maximum pressure to detect 69int zMin; // minimum pressure to detect 70int backlightTimer; // for backlight timeout 71int backLightState; // status of backlight 1 for on and 0 for off 72int backlightTimeDifference; 73int newBacklightTime; 74int oldBacklightTime; 75 76//end declarations 77//end declarations 78//end declarations 79//end declarations 80//end declarations 81//end declarations 82//end declarations 83//end declarations 84//end declarations 85 86//********************************************************* 87//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 88//********************************************************* 89 90// begin void setup 91// begin void setup 92// begin void setup 93// begin void setup 94// begin void setup 95// begin void setup 96// begin void setup 97// begin void setup 98// begin void setup 99// begin void setup 100// begin void setup 101void setup() { 102Serial.begin(115200); 103 oldButtonTime = millis(); 104 newButtonTime = millis(); 105 Tft.TFTinit(); // init TFT library 106 TFT_BL_ON; // turn on the background light 107 backLightState = 1; 108 x = 0; 109 y = 0; 110 z = 0; 111 buttonPressed = 4; 112 113 //////////////////////////////// 114 //// manually set variables //// 115 //////////////////////////////// 116 117 debounceTime = 1000; // button debounce in milliseconds 118 zMax = 460; // maximum pressure to detect 119 zMin = 100; // minimum pressure to detect 120 backlightTimer = 5000; // for backlight timeout 121 122 123 currentScreen = 0; 124 callScreen(); 125 126} //void setup() 127// end void setup 128// end void setup 129// end void setup 130// end void setup 131// end void setup 132// end void setup 133// end void setup 134// end void setup 135 136//********************************************************* 137//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 138//********************************************************* 139 140// begin void loop 141// begin void loop 142// begin void loop 143// begin void loop 144// begin void loop 145// begin void loop 146// begin void loop 147// begin void loop 148// begin void loop 149// begin void loop 150// begin void loop 151// begin void loop 152// begin void loop 153// begin void loop 154 155void loop() { 156 tftBacklightTimeout(); // check time and turn off backlight 157 tftDetect(); // gather information from touch screen touches 158 buttonTimeDifference = newButtonTime - oldButtonTime; 159 if(debounceTime < buttonTimeDifference){ 160 whatScreen(); 161 callScreen(); 162 oldButtonTime = newButtonTime; 163 showStuff(); // serial prints 164 tftDisplay(); // display x y coordinates on tft display 165 } 166} //void loop() 167 168// end of void loop 169// end of void loop 170// end of void loop 171// end of void loop 172// end of void loop 173// end of void loop 174// end of void loop 175// end of void loop 176// end of void loop 177// end of void loop 178// end of void loop 179// end of void loop 180// end of void loop 181// end of void loop 182// end of void loop 183 184//**************************************************************************************************** 185//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 186//**************************************************************************************************** 187///////////////////////////////////////////////////////////////////////////////////////////////////////// 188///////////////////////////////////////// functions /////////////////////////////////////////////////// 189///////////////////////////////////////////////////////////////////////////////////////////////////////// 190//**************************************************************************************************** 191//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 192//**************************************************************************************************** 193 194//--------------------------begin tftBacklightTimeout---------------------------------- 195void tftBacklightTimeout(){ 196 newBacklightTime = millis(); 197 if(backLightState = 0){ 198 backlightTimeDifference = newBacklightTime - oldBacklightTime; 199 if(backlightTimer > backlightTimeDifference){ 200 backlightTimeDifference = newBacklightTime - oldBacklightTime; 201 TFT_BL_ON; // turn on the background light 202 backLightState = 1; 203 oldBacklightTime = millis(); 204 } 205 } 206 if(backLightState = 1){ 207 backlightTimeDifference = newBacklightTime - oldBacklightTime; 208 if(backlightTimer < backlightTimeDifference){ 209 backlightTimeDifference = newBacklightTime - oldBacklightTime; 210 TFT_BL_OFF; // turn off the background light 211 backLightState = 0; 212 oldBacklightTime = millis(); 213 } 214 } 215} 216//--------------------------end tftBacklightTimeout---------------------------------- 217 218//**************************************************************************************************** 219//**************************************************************************************************** 220 221//--------------------------begin tftDetect---------------------------------- 222//--------------------------begin tftDetect---------------------------------- 223//--------------------------begin tftDetect---------------------------------- 224//--------------------------begin tftDetect---------------------------------- 225int tftDetect(){ 226 Point p = ts.getPoint(); 227 if(zMin<p.z && p.z<zMax){ 228 TFT_BL_ON; // turn on the background light 229 backLightState = 1; 230 oldBacklightTime = millis(); 231 newButtonTime = millis(); 232 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 233 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 234//Button 1 235 if(75<p.x && p.x<140){ 236 if(100<p.y && p.y<164){ 237 buttonPressed = 1; 238 } 239//Button 2 240 if(164<p.y && p.y<240){ 241 buttonPressed = 2; 242 } 243//Button 3 244 if(240<p.y && p.y<310){ 245 buttonPressed = 3; 246 } 247 } 248 } 249//Button 4 250 if(10<p.x && p.x<75){ 251 if(100<p.y && p.y<240){ 252 buttonPressed = 4; 253 } 254 } 255//Button 5 256 if(250<p.x && p.x<275){ 257 if(0<p.y && p.y<75){ 258 buttonPressed = 5; 259 } 260 } 261}//void tftDetect 262//--------------------------end tftDetect code---------------------------------- 263//--------------------------end tftDetect code---------------------------------- 264//--------------------------end tftDetect code---------------------------------- 265//--------------------------end tftDetect code---------------------------------- 266//--------------------------end tftDetect code---------------------------------- 267//**************************************************************************************************** 268//**************************************************************************************************** 269//-------------------------- begin whatScreen function ------------------------- 270//-------------------------- begin whatScreen function ------------------------- 271//-------------------------- begin whatScreen function ------------------------- 272//-------------------------- begin whatScreen function ------------------------- 273 274int whatScreen(){ 275 if(x == 0){ 276 if(buttonPressed == 1){ 277 x = x + 1; 278 Serial.println("x + 1"); 279 } 280 if(buttonPressed == 2){ 281 x = x + 2; 282 Serial.println("x + 2"); 283 } 284 if(buttonPressed == 3){ 285 x = x + 3; 286 Serial.println("x + 3"); 287 } 288 if(buttonPressed == 4){ 289 x = 0; 290 Serial.println("x = 0"); 291 } 292 if(buttonPressed == 5){ 293 x = 0; 294 y = 0; 295 z = 0; 296 Serial.println("xyz all 0"); 297 } 298 } 299 else if(x >> 0){ 300 if(y == 0){ 301 if(buttonPressed == 1){ 302 y = y + 10; 303 Serial.println("y + 10"); 304 } 305 if(buttonPressed == 2){ 306 y = y + 20; 307 Serial.println("y + 20"); 308 } 309 if(buttonPressed == 3){ 310 y = y + 30; 311 Serial.println("y + 30"); 312 } 313 if(buttonPressed == 4){ 314 x = 0; 315 Serial.println("x = 0"); 316 } 317 if(buttonPressed == 5){ 318 x = 0; 319 y = 0; 320 z = 0; 321 Serial.println("xyz all 0"); 322 } 323 } 324 else if (y >> 0){ 325 if(buttonPressed == 1){ 326 z = z + 100; 327 Serial.println("z + 100"); 328 } 329 if(buttonPressed == 2){ 330 z = z + 200; 331 Serial.println("z + 200"); 332 } 333 if(buttonPressed == 3){ 334 z = z + 300; 335 Serial.println("z + 300"); 336 } 337 if(buttonPressed == 4){ 338 if(z == 0){ 339 y = 0; 340 Serial.println("y = 0"); 341 } 342 else if(z >> 0){ 343 z = 0; 344 Serial.println("z = 0"); 345 } 346 } 347 if(buttonPressed == 5){ 348 x = 0; 349 y = 0; 350 z = 0; 351 Serial.println("xyz all 0"); 352 } 353 }//y>0 354 }//x>0 355 currentScreen = z+y+x; 356} 357//-------------------------- end whatScreen function ------------------------- 358//-------------------------- end whatScreen function ------------------------- 359//-------------------------- end whatScreen function ------------------------- 360//-------------------------- end whatScreen function ------------------------- 361//-------------------------- end whatScreen function ------------------------- 362 363//**************************************************************************************************** 364//**************************************************************************************************** 365 366//--------------------------begin arduino master data fetch calls---------------------------------- 367// call slave1 arduino for data 368// call slave2 arduino for data 369//--------------------------end arduino master data fetch calls------------------------------------ 370 371//**************************************************************************************************** 372//**************************************************************************************************** 373 374//--------------------------begin tftDisplay code---------------------------------- 375void tftDisplay(){ 376 Point p = ts.getPoint(); 377 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 378 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 379 Tft.fillRectangle(0, 160, 60, 30, BLACK); 380 Tft.drawNumber((p.x), 0, 160, 3, GREEN); 381 Tft.fillRectangle(180, 160, 60, 30, BLACK); 382 Tft.drawNumber((p.y), 180, 160, 3, GREEN); 383 Tft.fillRectangle(80, 160, 60, 30, BLACK); 384 Tft.drawNumber((buttonPressed), 80, 160, 3, GREEN); 385}// void tftDisplay 386//--------------------------end tftDisplay code------------------------------------ 387 388//**************************************************************************************************** 389//**************************************************************************************************** 390 391//-------------------------- begin slave1 data fetch function -------------------------- 392//-------------------------- end slave1 data fetch function -------------------------- 393 394//**************************************************************************************************** 395//**************************************************************************************************** 396 397//-------------------------- begin slave2 data fetch function -------------------------- 398//-------------------------- end slave2 data fetch function ------------------------- 399 400//**************************************************************************************************** 401//**************************************************************************************************** 402 403//-------------------------- begin serial display function -------------------------- 404void showStuff(){ 405 Serial.println("------/ last update /-------"); 406// Serial.println("------begin display-------"); 407 Serial.print("buttonPressed "); 408 Serial.println(buttonPressed); 409 Serial.print("x "); 410 Serial.println(x); 411 Serial.print("y "); 412 Serial.println(y); 413 Serial.print("z "); 414 Serial.println(z); 415 Serial.print("currentScreen "); 416 Serial.println(currentScreen); 417// Serial.println("-------end display--------"); 418 Serial.println(""); 419 Serial.println(""); 420 Serial.println(""); 421 } 422//-------------------------- end serial display function ------------------------- 423 424 425//**************************************************************************************************** 426//**************************************************************************************************** 427 428//--------------------------- Primary screen maps -------------------------------- 429/* 430******** 431updates needed 432******** 4331 ditch the contrast 4342 ditch the brightness 4353 setup screen timeout 436 437 438 439 440screen 0000 A)Home 441 screen 0001 a)settings 442 screen 0011 -brightness 443 screen 0011 -contrast 444 screen 0011 -screen lock time out 445 screen 0001 b)sensor monitors 446 screen 0021 -pir 447 screen 0121 *report pir detection 448 screen 0021 -sound 449 screen 0221 *sense alexa sound 450 screen 0221 *sense graves sound 451 screen 0221 *report mouth servo position 452 screen 0221 *adjust sensitivity? 453 screen 0021 -head potentiometer 454 screen 0021 -bluetooth 455 screen 0001 c)bluetooth 456 screen 0031 -on 457 screen 0031 -off 458 screen 0031 -monitor 459screen 0000 B)Mouth Control 460 screen 0002 a)test button 461 screen 0012 -open 462 screen 0012 -close 463 screen 0012 -push button chicken switch 464 screen 0002 b)sound sensors on/off 465 screen 0022 -alexa sense 466 screen 0122 *on 467 screen 0122 *off 468 screen 0122 *monitor sensor 469 screen 0022 -graves sense 470 screen 0222 *on 471 screen 0222 *off 472 screen 0222 *monitor sensors 473 screen 0002 c)sound sensor status 474 screen 0032 -alexa 475 screen 0032 -graves 476screen 0000 C)Head Control 477 screen 0003 a)pir on/off 478 screen 0013 -on 479 screen 0013 -off 480 screen 0013 -sensor 481 screen 0003 b)manual point 482 screen 0023 -slider 483*/ 484//**************************************************************************************************** 485//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 486//**************************************************************************************************** 487//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 488//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 489//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 490//**************************************************************************************************** 491//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 492//**************************************************************************************************** 493 494//-------------------------- begin callScreen function ------------------------- 495//-------------------------- begin callScreen function ------------------------- 496//-------------------------- begin callScreen function ------------------------- 497//-------------------------- begin callScreen function ------------------------- 498//-------------------------- begin callScreen function ------------------------- 499//-------------------------- begin callScreen function ------------------------- 500//-------------------------- begin callScreen function ------------------------- 501//-------------------------- begin callScreen function ------------------------- 502//-------------------------- begin callScreen function ------------------------- 503//-------------------------- begin callScreen function ------------------------- 504//-------------------------- begin callScreen function ------------------------- 505 506int callScreen(){ 507 Tft.fillRectangle(0, 0, 240, 320, BLACK); 508 509//<><><><><><><><><><><><><><><><><><><><><><><><> 510//<><><><><><><><> begin screen 0000 master <><><><><><><><> 511//<><><><><><><><><><><><><><><><><><><><><><><><> 512if(currentScreen == 0){ 513 // " " 514 Tft.drawString("GRAVES",0,5,4, GREEN); 515 Tft.drawString("INTERFACE",10,50,4,GREEN); 516 Tft.drawString("Home", 80,130, 3, GREEN); 517 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 518 Tft.drawString("Head Control", 10, 260, 3, GREEN); 519} 520//<><><><><><><><><><><><><><><><><><><><><><><><> 521//<><><><><><><><> end screen 0000 master <><><><><><><><><> 522//<><><><><><><><><><><><><><><><><><><><><><><><> 523 524//<><><><><><><><><><><><><><><><><><><><><><><><> 525//<><><><><><><><> begin screen 0001 <><><><><><><><> 526//<><><><><><><><><><><><><><><><><><><><><><><><> 527 if(currentScreen == 1){ 528 // " " 529 Tft.drawString("MEGA 2560",00,5,4,BLUE); 530 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 531 Tft.drawString("Settings", 10,130, 3, BLUE); 532 Tft.drawString("Sensors", 20, 195, 3, BLUE); 533 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 534 Tft.drawString("<", 0, 160, 3, GREEN); // back button 535} 536//<><><><><><><><><><><><><><><><><><><><><><><><> 537//<><><><><><><><> end screen 0001 <><><><><><><><><> 538//<><><><><><><><><><><><><><><><><><><><><><><><> 539 540//<><><><><><><><><><><><><><><><><><><><><><><><> 541//<><><><><><><><> begin screen 0011 <><><><><><><><> 542//<><><><><><><><><><><><><><><><><><><><><><><><> 543 if(currentScreen == 11){ 544 // " " 545 Tft.drawString("MEGA 2560",00,5,4,BLUE); 546 Tft.drawString("SETTINGS",10,50,4,YELLOW); 547 Tft.drawString("Brightness", 80,130, 3, BLUE); 548 Tft.drawString("Contrast", 05, 195, 3, GREEN); 549 Tft.drawString("Timeout", 10, 260, 3, GREEN); 550 Tft.drawString("<", 0, 160, 3, GREEN); // back button 551} 552 553//<><><><><><><><><><><><><><><><><><><><><><><><> 554//<><><><><><><><> end screen 0011 <><><><><><><><><> 555//<><><><><><><><><><><><><><><><><><><><><><><><> 556 557//<><><><><><><><><><><><><><><><><><><><><><><><> 558//<><><><><><><><> begin screen 0021 <><><><><><><><> 559//<><><><><><><><><><><><><><><><><><><><><><><><> 560 if(currentScreen == 21){ 561 // " " 562 Tft.drawString("MEGA 2560",00,5,4,BLUE); 563 Tft.drawString("SENSORS",10,50,4,YELLOW); 564 Tft.drawString("PIR Array", 80,130, 3, BLUE); 565 Tft.drawString("Sound", 05, 195, 3, GREEN); 566 Tft.drawString("Head Position", 10, 260, 3, GREEN); 567 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 568 Tft.drawString("<", 0, 160, 3, GREEN); // back button 569} 570//<><><><><><><><><><><><><><><><><><><><><><><><> 571//<><><><><><><><> end screen 0021 <><><><><><><><><> 572//<><><><><><><><><><><><><><><><><><><><><><><><> 573 574//<><><><><><><><><><><><><><><><><><><><><><><><> 575//<><><><><><><><> begin screen 0121 <><><><><><><><> 576//<><><><><><><><><><><><><><><><><><><><><><><><> 577 if(currentScreen == 121){ 578 // " " 579 Tft.drawString("PIR",0,5,4,BLUE); 580 Tft.drawString("ARRAY",10,50,4,YELLOW); 581 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 582 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 583 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 584 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 585 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 586 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 587 Tft.drawString("<", 0, 160, 3, GREEN); // back button 588} 589//<><><><><><><><><><><><><><><><><><><><><><><><> 590//<><><><><><><><> end screen 0121 <><><><><><><><><> 591//<><><><><><><><><><><><><><><><><><><><><><><><> 592 593//<><><><><><><><><><><><><><><><><><><><><><><><> 594//<><><><><><><><> begin screen 0221 <><><><><><><><> 595//<><><><><><><><><><><><><><><><><><><><><><><><> 596 if(currentScreen == 221){ 597 // " " 598 Tft.drawString("SOUND",0,5,4,BLUE); 599 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 600 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 601 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 602 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 603 Tft.drawString("<", 0, 160, 3, GREEN); // back button 604} 605//<><><><><><><><><><><><><><><><><><><><><><><><> 606//<><><><><><><><> end screen 0221 <><><><><><><><><> 607//<><><><><><><><><><><><><><><><><><><><><><><><> 608 609//<><><><><><><><><><><><><><><><><><><><><><><><> 610//<><><><><><><><> begin screen 0031 <><><><><><><><> 611//<><><><><><><><><><><><><><><><><><><><><><><><> 612 if(currentScreen == 31){ 613 // " " 614 Tft.drawString("Bluetooth",0,5,4,BLUE); 615 Tft.drawString("Control",10,50,4,YELLOW); 616 Tft.drawString("On", 80,130, 3, BLUE); 617 Tft.drawString("Off", 05, 195, 3, GREEN); 618 Tft.drawString("Monitor", 10, 260, 3, GREEN); 619 Tft.drawString("<", 0, 160, 3, GREEN); // back button 620} 621//<><><><><><><><><><><><><><><><><><><><><><><><> 622//<><><><><><><><> end screen 0031 <><><><><><><><><> 623//<><><><><><><><><><><><><><><><><><><><><><><><> 624 625//<><><><><><><><><><><><><><><><><><><><><><><><> 626//<><><><><><><><> begin screen 0002 <><><><><><><><> 627//<><><><><><><><><><><><><><><><><><><><><><><><> 628 if(currentScreen == 2){ 629 // " " 630 Tft.drawString("Mouth",0,5,4,BLUE); 631 Tft.drawString("Control",10,50,4,YELLOW); 632 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 633 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 634 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 635 Tft.drawString("<", 0, 160, 3, GREEN); // back button 636} 637//<><><><><><><><><><><><><><><><><><><><><><><><> 638//<><><><><><><><> end screen 0002 <><><><><><><><><> 639//<><><><><><><><><><><><><><><><><><><><><><><><> 640 641 642//<><><><><><><><><><><><><><><><><><><><><><><><> 643//<><><><><><><><> begin screen 0012 <><><><><><><><> 644//<><><><><><><><><><><><><><><><><><><><><><><><> 645 if(currentScreen == 12){ 646 // " " 647 Tft.drawString("Jaw Test",0,5,4,BLUE); 648 Tft.drawString("Operations",10,50,4,YELLOW); 649 Tft.drawString("Open", 80,130, 3, BLUE); 650 Tft.drawString("Close", 05, 195, 3, GREEN); 651 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 652 Tft.drawString("<", 0, 160, 3, GREEN); // back button 653} 654//<><><><><><><><><><><><><><><><><><><><><><><><> 655//<><><><><><><><> end screen 0012 <><><><><><><><><> 656//<><><><><><><><><><><><><><><><><><><><><><><><> 657 658 659//<><><><><><><><><><><><><><><><><><><><><><><><> 660//<><><><><><><><> begin screen 0022 <><><><><><><><> 661//<><><><><><><><><><><><><><><><><><><><><><><><> 662 if(currentScreen == 22){ 663 // " " 664 Tft.drawString("Sound",0,5,4,BLUE); 665 Tft.drawString("Sensors",10,50,4,YELLOW); 666 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 667 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 668 Tft.drawString("Monitor", 10, 260, 3, GREEN); 669 Tft.drawString("<", 0, 160, 3, GREEN); // back button 670} 671//<><><><><><><><><><><><><><><><><><><><><><><><> 672//<><><><><><><><> end screen 0022 <><><><><><><><><> 673//<><><><><><><><><><><><><><><><><><><><><><><><> 674 675 676 677//<><><><><><><><><><><><><><><><><><><><><><><><> 678//<><><><><><><><> begin screen 0122 <><><><><><><><> 679//<><><><><><><><><><><><><><><><><><><><><><><><> 680 if(currentScreen == 122){ 681 // " " 682 Tft.drawString("Alexa Sense",0,5,4,BLUE); 683 Tft.drawString("Operations",10,50,4,YELLOW); 684 Tft.drawString("On", 80,130, 3, BLUE); 685 Tft.drawString("Off", 05, 195, 3, GREEN); 686 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 687 Tft.drawString("<", 0, 160, 3, GREEN); // back button 688} 689//<><><><><><><><><><><><><><><><><><><><><><><><> 690//<><><><><><><><> end screen 0122 <><><><><><><><><> 691//<><><><><><><><><><><><><><><><><><><><><><><><> 692 693//<><><><><><><><><><><><><><><><><><><><><><><><> 694//<><><><><><><><> begin screen 0222 <><><><><><><><> 695//<><><><><><><><><><><><><><><><><><><><><><><><> 696 if(currentScreen == 222){ 697 // " " 698 Tft.drawString("Graves Sense",0,5,4,BLUE); 699 Tft.drawString("Operations",10,50,4,YELLOW); 700 Tft.drawString("On", 80,130, 3, BLUE); 701 Tft.drawString("Off", 05, 195, 3, GREEN); 702 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 703 Tft.drawString("<", 0, 160, 3, GREEN); // back button 704} 705//<><><><><><><><><><><><><><><><><><><><><><><><> 706//<><><><><><><><> end screen 0222 <><><><><><><><><> 707//<><><><><><><><><><><><><><><><><><><><><><><><> 708 709//<><><><><><><><><><><><><><><><><><><><><><><><> 710//<><><><><><><><> begin screen 0032 <><><><><><><><> 711//<><><><><><><><><><><><><><><><><><><><><><><><> 712 if(currentScreen == 32){ 713 // " " 714 Tft.drawString("Sound Sense",0,5,4,BLUE); 715 Tft.drawString("Monitors",10,50,4,YELLOW); 716 Tft.drawString("Alexa", 80,130, 3, BLUE); 717 Tft.drawString("Graves", 05, 195, 3, GREEN); 718 Tft.drawString("<", 0, 160, 3, GREEN); // back button 719} 720//<><><><><><><><><><><><><><><><><><><><><><><><> 721//<><><><><><><><> end screen 0032 <><><><><><><><><> 722//<><><><><><><><><><><><><><><><><><><><><><><><> 723 724//<><><><><><><><><><><><><><><><><><><><><><><><> 725//<><><><><><><><> begin screen 0003 <><><><><><><><> 726//<><><><><><><><><><><><><><><><><><><><><><><><> 727 if(currentScreen == 3){ 728 // " " 729 Tft.drawString("Head Control",0,5,4,BLUE); 730 Tft.drawString("Operations",10,50,4,YELLOW); 731 Tft.drawString("PIR Array", 80,130, 3, BLUE); 732 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 733 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 734 Tft.drawString("<", 0, 160, 3, GREEN); // back button 735} 736//<><><><><><><><><><><><><><><><><><><><><><><><> 737//<><><><><><><><> end screen 0003 <><><><><><><><><> 738//<><><><><><><><><><><><><><><><><><><><><><><><> 739 740//<><><><><><><><><><><><><><><><><><><><><><><><> 741//<><><><><><><><> begin screen 0013 <><><><><><><><> 742//<><><><><><><><><><><><><><><><><><><><><><><><> 743 if(currentScreen == 13){ 744 // " " 745 Tft.drawString("PIR Control",0,5,4,BLUE); 746 Tft.drawString("Operations",10,50,4,YELLOW); 747 Tft.drawString("On", 80,130, 3, BLUE); 748 Tft.drawString("Off", 05, 195, 3, GREEN); 749 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 750 Tft.drawString("<", 0, 160, 3, GREEN); // back button 751} 752//<><><><><><><><><><><><><><><><><><><><><><><><> 753//<><><><><><><><> end screen 0013 <><><><><><><><><> 754//<><><><><><><><><><><><><><><><><><><><><><><><> 755 756//<><><><><><><><><><><><><><><><><><><><><><><><> 757//<><><><><><><><> begin screen 0023 <><><><><><><><> 758//<><><><><><><><><><><><><><><><><><><><><><><><> 759 if(currentScreen == 23){ 760 // " " 761 Tft.drawString("Head Control",0,5,4,BLUE); 762 Tft.drawString("Manual Point",10,50,4,YELLOW); 763 Tft.drawString("Slider", 80,130, 3, BLUE); 764 Tft.drawString("<", 0, 160, 3, GREEN); // back button 765} 766//<><><><><><><><><><><><><><><><><><><><><><><><> 767//<><><><><><><><> end screen 0023 <><><><><><><><><> 768//<><><><><><><><><><><><><><><><><><><><><><><><> 769 770 771////<><><><><><><><><><><><><><><><><><><><><><><><> 772////<><><><><><><><> begin screen lost <><><><><><><><> 773////<><><><><><><><><><><><><><><><><><><><><><><><> 774// else if(currentScreen){ 775// // " " 776// Tft.drawString("Screen not",0,5,3,BLUE); 777// Tft.drawString("found. Please",40,50,3,YELLOW); 778// Tft.drawString("use the back", 80,130, 3, BLUE); 779// Tft.drawString("button to", 05, 195, 3, GREEN); 780// Tft.drawString("return to fun", 10, 260, 3, GREEN); 781// Tft.drawString("<", 0, 160, 3, GREEN); // back button 782//} 783////<><><><><><><><><><><><><><><><><><><><><><><><> 784////<><><><><><><><> end screen lost <><><><><><><><><> 785////<><><><><><><><><><><><><><><><><><><><><><><><> 786 787}// callScreen 788//-------------------------- end callScreen function ------------------------- 789//-------------------------- end callScreen function ------------------------- 790//-------------------------- end callScreen function ------------------------- 791//-------------------------- end callScreen function ------------------------- 792//-------------------------- end callScreen function ------------------------- 793//-------------------------- end callScreen function ------------------------- 794//-------------------------- end callScreen function ------------------------- 795//-------------------------- end callScreen function ------------------------- 796//-------------------------- end callScreen function ------------------------- 797//-------------------------- end callScreen function ------------------------- 798//-------------------------- end callScreen function ------------------------- 799//-------------------------- end callScreen function ------------------------- 800//-------------------------- end callScreen function ------------------------- 801 802 803//**************************************************************************************************** 804//**************************************************************************************************** 805 806 807 808 809 810 811 812//**************************************************************************************************** 813//**************************************************************************************************** 814 815// fin
buttons again
c_cpp
setup new buttons for slider and on off
1/* 2last edit sun oct 14 2018 later in the day 3 4 5gravesmegamaster 6 7graves project 8arduino MEGA 2650 9Master 10coded from scratch by wylie jones 11wyliejones@gmail.com 12 13Graves multi arduino build 10/2018 14Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 15two arduino uno's 16slave1 arduino uno to sense sound from graves and echo dot to control mouth 17slave2 arduino uno to control passive sensor array and head servo 18 19sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 20 21 analogue pin speaker + 22 \ / (red from speaker) 23 \ / 24 \ / 25 *--------[=]-----------*---------[=]----------* 26 | resistor \ resistor | 27 | \ | 28 |(red with white) \ |to arduino ground (black with white) 29to arduino 5v+ speaker - 30 (black from speaker) 31 32*/ 33//end notes 34//end notes 35//end notes 36//end notes 37//end notes 38//end notes 39 40 41//********************************************************* 42//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 43//********************************************************* 44 45 46//begin declarations 47//begin declarations 48//begin declarations 49//begin declarations 50//begin declarations 51//begin declarations 52//begin declarations 53 54//#include <TFT.h> 55//#include <Servo.h> 56//#include <stdint.h> 57//#include <SD.h> 58#include <TFTv2.h> 59#include <SPI.h> 60#include <SeeedTouchScreen.h> 61 62//const int PIN_SD_CS = 4; // pin of sd card 63 64TouchScreen ts = TouchScreen(XP, YP, XM, YM); 65int buttonPressed; // stores which button was pressed 66unsigned long newButtonTime; // debounce 67unsigned long oldButtonTime; // debounce 68unsigned long buttonTimeDifference; // debounce 69unsigned long debounceTime; // debounce 70int currentScreen; // identifies current screen by adding x y and z 71int x; // for ones 72int y; // for tens 73int z; // for hundreds 74 75int zMax; // maximum pressure to detect 76int zMin; // minimum pressure to detect 77unsigned long backlightTimer; // for backlight timeout 78int backLightState; // status of backlight 1 for on and 0 for off 79unsigned long backlightTimeDifference; 80unsigned long newBacklightTime; 81unsigned long oldBacklightTime; 82 83int incomingMouthByte; 84int outgoingMouthByte; 85int mouthOnOff; 86int incomingHeadByte; 87int outgoingHeadByte; 88int headOnOff; 89 90//end declarations 91//end declarations 92//end declarations 93//end declarations 94//end declarations 95//end declarations 96//end declarations 97//end declarations 98//end declarations 99 100//********************************************************* 101//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 102//********************************************************* 103 104// begin void setup 105// begin void setup 106// begin void setup 107// begin void setup 108// begin void setup 109// begin void setup 110// begin void setup 111// begin void setup 112// begin void setup 113// begin void setup 114// begin void setup 115void setup() { 116Serial.begin(9600); 117 oldButtonTime = millis(); 118 newButtonTime = millis(); 119 Tft.TFTinit(); // init TFT library 120 TFT_BL_ON; // turn on the background light 121 backLightState = 1; 122 x = 0; 123 y = 0; 124 z = 0; 125 buttonPressed = 4; 126incomingHeadByte = 0; 127incomingMouthByte = 0; 128 129 //////////////////////////////// 130 //// manually set variables //// 131 //////////////////////////////// 132 133 debounceTime = 1000; // button debounce in milliseconds 134 zMax = 460; // maximum pressure to detect 135 zMin = 100; // minimum pressure to detect 136 backlightTimer = 5000; // for backlight timeout 137 138 139 currentScreen = 0; 140 callScreen(); 141 142} //void setup() 143// end void setup 144// end void setup 145// end void setup 146// end void setup 147// end void setup 148// end void setup 149// end void setup 150// end void setup 151 152//********************************************************* 153//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 154//********************************************************* 155 156// begin void loop 157// begin void loop 158// begin void loop 159// begin void loop 160// begin void loop 161// begin void loop 162// begin void loop 163// begin void loop 164// begin void loop 165// begin void loop 166// begin void loop 167// begin void loop 168// begin void loop 169// begin void loop 170 171void loop() { 172 tftBacklightTimeout( ); // check time and turn off backlight 173 tftButtonGroup0(); // gather information from touch screen touches 174 buttonTimeDifference = newButtonTime - oldButtonTime; 175 if(debounceTime < buttonTimeDifference){ 176 whatScreen(); 177 callScreen(); 178 oldButtonTime = newButtonTime; 179 showStuff(); // serial prints 180 tftDisplay(); // display x y coordinates on tft display 181 } 182// serialDoStuff(); 183} //void loop() 184 185// end of void loop 186// end of void loop 187// end of void loop 188// end of void loop 189// end of void loop 190// end of void loop 191// end of void loop 192// end of void loop 193// end of void loop 194// end of void loop 195// end of void loop 196// end of void loop 197// end of void loop 198// end of void loop 199// end of void loop 200 201//**************************************************************************************************** 202//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 203//**************************************************************************************************** 204///////////////////////////////////////////////////////////////////////////////////////////////////////// 205///////////////////////////////////////// functions /////////////////////////////////////////////////// 206///////////////////////////////////////////////////////////////////////////////////////////////////////// 207//**************************************************************************************************** 208//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 209//**************************************************************************************************** 210 211//--------------------------begin tftBacklightTimeout---------------------------------- 212void tftBacklightTimeout(){ 213 newBacklightTime = millis(); 214 if(backLightState = 0){ 215 backlightTimeDifference = newBacklightTime - oldBacklightTime; 216 if(backlightTimer > backlightTimeDifference){ 217 backlightTimeDifference = newBacklightTime - oldBacklightTime; 218 TFT_BL_ON; // turn on the background light 219 backLightState = 1; 220 oldBacklightTime = millis(); 221 } 222 } 223 if(backLightState = 1){ 224 backlightTimeDifference = newBacklightTime - oldBacklightTime; 225 if(backlightTimer < backlightTimeDifference){ 226 backlightTimeDifference = newBacklightTime - oldBacklightTime; 227 TFT_BL_OFF; // turn off the background light 228 backLightState = 0; 229 oldBacklightTime = millis(); 230 } 231 } 232} 233//--------------------------end tftBacklightTimeout---------------------------------- 234 235//**************************************************************************************************** 236//**************************************************************************************************** 237 238//--------------------------begin tftButtonGroup0---------------------------------- 239//--------------------------begin tftButtonGroup0---------------------------------- 240//--------------------------begin tftButtonGroup0---------------------------------- 241//--------------------------begin tftButtonGroup0---------------------------------- 242int tftButtonGroup0(){ 243 Point p = ts.getPoint(); 244 if(zMin<p.z && p.z<zMax){ 245 TFT_BL_ON; // turn on the background light 246 backLightState = 1; 247 oldBacklightTime = millis(); 248 newButtonTime = millis(); 249 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 250 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 251//Button 1 252 if(75<p.x && p.x<140){ 253 if(100<p.y && p.y<164){ 254 buttonPressed = 1; 255 } 256//Button 2 257 if(164<p.y && p.y<240){ 258 buttonPressed = 2; 259 } 260//Button 3 261 if(240<p.y && p.y<310){ 262 buttonPressed = 3; 263 } 264 } 265 } 266//Button 4 267 if(10<p.x && p.x<75){ 268 if(100<p.y && p.y<240){ 269 buttonPressed = 4; 270 } 271 } 272//Button 5 273 if(250<p.x && p.x<275){ 274 if(0<p.y && p.y<75){ 275 buttonPressed = 5; 276 } 277 } 278}//void tftButtonGroup0 279//--------------------------end tftButtonGroup0 code---------------------------------- 280//--------------------------end tftButtonGroup0 code---------------------------------- 281//--------------------------end tftButtonGroup0 code---------------------------------- 282//--------------------------end tftButtonGroup0 code---------------------------------- 283//--------------------------end tftButtonGroup0 code---------------------------------- 284//**************************************************************************************************** 285//**************************************************************************************************** 286 287//--------------------------begin tftButtonGroup1---------------------------------- 288//--------------------------begin tftButtonGroup1---------------------------------- 289//--------------------------begin tftButtonGroup1---------------------------------- 290//--------------------------begin tftButtonGroup1---------------------------------- 291int tftButtonGroup1(){ // for mouth 292 Point p = ts.getPoint(); 293 if(zMin<p.z && p.z<zMax){ 294 TFT_BL_ON; // turn on the background light 295 backLightState = 1; 296 oldBacklightTime = millis(); 297 newButtonTime = millis(); 298 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 299 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 300//Button 1 301 if(75<p.x && p.x<140){ 302 if(100<p.y && p.y<164){ 303 mouthOnOff = 1; // on 304 } 305//Button 2 306 if(164<p.y && p.y<240){ 307 mouthOnOff = 0; // off 308 } 309//Button 3 310// if(240<p.y && p.y<310){ 311// buttonPressed = 3; 312// } 313// } 314 } 315//Button 4 316 if(10<p.x && p.x<75){ 317 if(100<p.y && p.y<240){ 318 buttonPressed = 4; 319 } 320 } 321}//void tftButtonGroup1 322//--------------------------end tftButtonGroup1 code---------------------------------- 323//--------------------------end tftButtonGroup1 code---------------------------------- 324//--------------------------end tftButtonGroup1 code---------------------------------- 325//--------------------------end tftButtonGroup1 code---------------------------------- 326//--------------------------end tftButtonGroup1 code---------------------------------- 327//**************************************************************************************************** 328//**************************************************************************************************** 329 330//--------------------------begin tftButtonGroup2---------------------------------- 331//--------------------------begin tftButtonGroup2---------------------------------- 332//--------------------------begin tftButtonGroup2---------------------------------- 333//--------------------------begin tftButtonGroup2---------------------------------- 334int tftButtonGroup2(){ // for head 335 Point p = ts.getPoint(); 336 if(zMin<p.z && p.z<zMax){ 337 TFT_BL_ON; // turn on the background light 338 backLightState = 1; 339 oldBacklightTime = millis(); 340 newButtonTime = millis(); 341 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 342 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 343//Button 1 344 if(75<p.x && p.x<140){ 345 if(100<p.y && p.y<164){ 346 headOnOff = 1; // on 347 } 348//Button 2 349 if(164<p.y && p.y<240){ 350 headOnOff = 0; // off 351 } 352//Button 3 353// if(240<p.y && p.y<310){ 354// buttonPressed = 3; 355// } 356// } 357 } 358//Button 4 359 if(10<p.x && p.x<75){ 360 if(100<p.y && p.y<240){ 361 buttonPressed = 4; 362 } 363 } 364}//void tftButtonGroup2 365//--------------------------end tftButtonGroup2 code---------------------------------- 366//--------------------------end tftButtonGroup2 code---------------------------------- 367//--------------------------end tftButtonGroup2 code---------------------------------- 368//--------------------------end tftButtonGroup2 code---------------------------------- 369//--------------------------end tftButtonGroup2 code---------------------------------- 370//**************************************************************************************************** 371//**************************************************************************************************** 372//-------------------------- begin whatScreen function ------------------------- 373//-------------------------- begin whatScreen function ------------------------- 374//-------------------------- begin whatScreen function ------------------------- 375//-------------------------- begin whatScreen function ------------------------- 376 377int whatScreen(){ 378 if(x == 0){ 379 if(buttonPressed == 1){ 380 x = x + 1; 381 Serial.println("x + 1"); 382 } 383 if(buttonPressed == 2){ 384 x = x + 2; 385 Serial.println("x + 2"); 386 } 387 if(buttonPressed == 3){ 388 x = x + 3; 389 Serial.println("x + 3"); 390 } 391 if(buttonPressed == 4){ 392 x = 0; 393 Serial.println("x = 0"); 394 } 395 if(buttonPressed == 5){ 396 x = 0; 397 y = 0; 398 z = 0; 399 Serial.println("xyz all 0"); 400 } 401 } 402 else if(x >> 0){ 403 if(y == 0){ 404 if(buttonPressed == 1){ 405 y = y + 10; 406 Serial.println("y + 10"); 407 } 408 if(buttonPressed == 2){ 409 y = y + 20; 410 Serial.println("y + 20"); 411 } 412 if(buttonPressed == 3){ 413 y = y + 30; 414 Serial.println("y + 30"); 415 } 416 if(buttonPressed == 4){ 417 x = 0; 418 Serial.println("x = 0"); 419 } 420 if(buttonPressed == 5){ 421 x = 0; 422 y = 0; 423 z = 0; 424 Serial.println("xyz all 0"); 425 } 426 } 427 else if (y >> 0){ 428 if(buttonPressed == 1){ 429 z = z + 100; 430 Serial.println("z + 100"); 431 } 432 if(buttonPressed == 2){ 433 z = z + 200; 434 Serial.println("z + 200"); 435 } 436 if(buttonPressed == 3){ 437 z = z + 300; 438 Serial.println("z + 300"); 439 } 440 if(buttonPressed == 4){ 441 if(z == 0){ 442 y = 0; 443 Serial.println("y = 0"); 444 } 445 else if(z >> 0){ 446 z = 0; 447 Serial.println("z = 0"); 448 } 449 } 450 if(buttonPressed == 5){ 451 x = 0; 452 y = 0; 453 z = 0; 454 Serial.println("xyz all 0"); 455 } 456 }//y>0 457 }//x>0 458 currentScreen = z+y+x; 459} 460//-------------------------- end whatScreen function ------------------------- 461//-------------------------- end whatScreen function ------------------------- 462//-------------------------- end whatScreen function ------------------------- 463//-------------------------- end whatScreen function ------------------------- 464//-------------------------- end whatScreen function ------------------------- 465 466//**************************************************************************************************** 467//**************************************************************************************************** 468 469//--------------------------begin mouthUnoTxRx---------------------------------- 470 471void mouthUnoTxRx(){ 472 473 //mouthOnOff code? 474 Serial1.write(1); // send a byte with the value 45 475 if (Serial1.available() > 0) { 476 // read the incoming byte: 477 incomingMouthByte = Serial1.read(); 478 } 479} 480 481//--------------------------end mouthUnoTxRx -------------------------------------- 482//--------------------------begin headUnoTxRx -------------------------------------- 483 484// call slave1 arduino for data 485 //headOnOff code? 486void headUnoTxRx(){ 487 Serial2.write(1); // send a byte with the value 45 488 if (Serial2.available() > 0) { 489 // read the incoming byte: 490 incomingHeadByte = Serial2.read(); 491 } 492 493} 494 495// call slave2 arduino for data 496//--------------------------end headUnoTxRx -------------------------------------- 497 498//**************************************************************************************************** 499//**************************************************************************************************** 500 501//--------------------------begin tftDisplay code---------------------------------- 502void tftDisplay(){ 503 Point p = ts.getPoint(); 504 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 505 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 506 Tft.fillRectangle(0, 160, 60, 30, BLACK); 507 Tft.drawNumber((p.x), 0, 160, 3, GREEN); 508 Tft.fillRectangle(180, 160, 60, 30, BLACK); 509 Tft.drawNumber((p.y), 180, 160, 3, GREEN); 510 Tft.fillRectangle(80, 160, 60, 30, BLACK); 511 Tft.drawNumber((buttonPressed), 80, 160, 3, GREEN); 512}// void tftDisplay 513//--------------------------end tftDisplay code------------------------------------ 514 515//**************************************************************************************************** 516//**************************************************************************************************** 517 518//-------------------------- begin mouth on off function -------------------------- 519//-------------------------- end mouth on off function -------------------------- 520 521//**************************************************************************************************** 522//**************************************************************************************************** 523 524//-------------------------- begin head on off function -------------------------- 525//-------------------------- end head on off function ------------------------- 526 527//**************************************************************************************************** 528//**************************************************************************************************** 529 530//-------------------------- begin serial display function -------------------------- 531void showStuff(){ 532 Serial.println("------/ last update /-------"); 533// Serial.println("------begin display-------"); 534 Serial.print("buttonPressed "); 535 Serial.println(buttonPressed); 536 Serial.print("x "); 537 Serial.println(x); 538 Serial.print("y "); 539 Serial.println(y); 540 Serial.print("z "); 541 Serial.println(z); 542 Serial.print("currentScreen "); 543 Serial.println(currentScreen); 544// Serial.println("-------end display--------"); 545 Serial.println(""); 546 Serial.println(""); 547 Serial.println(""); 548 } 549//-------------------------- end serial display function ------------------------- 550 551 552//**************************************************************************************************** 553//**************************************************************************************************** 554 555//--------------------------- Primary screen maps -------------------------------- 556/* 557******** 558updates needed 559******** 5601 ditch the contrast 5612 ditch the brightness 5623 setup screen timeout 563 564 565 566 567screen 0000 A)Home 568 screen 0001 a)settings 569 screen 0011 -brightness 570 screen 0011 -contrast 571 screen 0011 -screen lock time out 572 screen 0001 b)sensor monitors 573 screen 0021 -pir 574 screen 0121 *report pir detection 575 screen 0021 -sound 576 screen 0221 *sense alexa sound 577 screen 0221 *sense graves sound 578 screen 0221 *report mouth servo position 579 screen 0221 *adjust sensitivity? 580 screen 0021 -head potentiometer 581 screen 0021 -bluetooth 582 screen 0001 c)bluetooth 583 screen 0031 -on 584 screen 0031 -off 585 screen 0031 -monitor 586screen 0000 B)Mouth Control 587 screen 0002 a)test button 588 screen 0012 -open 589 screen 0012 -close 590 screen 0012 -push button chicken switch 591 screen 0002 b)sound sensors on/off 592 screen 0022 -alexa sense 593 screen 0122 *on 594 screen 0122 *off 595 screen 0122 *monitor sensor 596 screen 0022 -graves sense 597 screen 0222 *on 598 screen 0222 *off 599 screen 0222 *monitor sensors 600 screen 0002 c)sound sensor status 601 screen 0032 -alexa 602 screen 0032 -graves 603screen 0000 C)Head Control 604 screen 0003 a)pir on/off 605 screen 0013 -on 606 screen 0013 -off 607 screen 0013 -sensor 608 screen 0003 b)manual point 609 screen 0023 -slider 610*/ 611//**************************************************************************************************** 612//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 613//**************************************************************************************************** 614//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 615//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 616//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 617//**************************************************************************************************** 618//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 619//**************************************************************************************************** 620 621//-------------------------- begin callScreen function ------------------------- 622//-------------------------- begin callScreen function ------------------------- 623//-------------------------- begin callScreen function ------------------------- 624//-------------------------- begin callScreen function ------------------------- 625//-------------------------- begin callScreen function ------------------------- 626//-------------------------- begin callScreen function ------------------------- 627//-------------------------- begin callScreen function ------------------------- 628//-------------------------- begin callScreen function ------------------------- 629//-------------------------- begin callScreen function ------------------------- 630//-------------------------- begin callScreen function ------------------------- 631//-------------------------- begin callScreen function ------------------------- 632 633int callScreen(){ 634 Tft.fillRectangle(0, 0, 240, 320, BLACK); 635 636//<><><><><><><><><><><><><><><><><><><><><><><><> 637//<><><><><><><><> begin screen 0000 master <><><><><><><><> 638//<><><><><><><><><><><><><><><><><><><><><><><><> 639if(currentScreen == 0){ 640 // " " 641 Tft.drawString("GRAVES",0,5,4, GREEN); 642 Tft.drawString("INTERFACE",10,50,4,GREEN); 643 Tft.drawString("Home", 80,130, 3, GREEN); 644 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 645 Tft.drawString("Head Control", 10, 260, 3, GREEN); 646} 647//<><><><><><><><><><><><><><><><><><><><><><><><> 648//<><><><><><><><> end screen 0000 master <><><><><><><><><> 649//<><><><><><><><><><><><><><><><><><><><><><><><> 650 651//<><><><><><><><><><><><><><><><><><><><><><><><> 652//<><><><><><><><> begin screen 0001 <><><><><><><><> 653//<><><><><><><><><><><><><><><><><><><><><><><><> 654 if(currentScreen == 1){ 655 // " " 656 Tft.drawString("MEGA 2560",00,5,4,BLUE); 657 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 658 Tft.drawString("Settings", 10,130, 3, BLUE); 659 Tft.drawString("Sensors", 20, 195, 3, BLUE); 660 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 661 Tft.drawString("<", 0, 160, 3, GREEN); // back button 662} 663//<><><><><><><><><><><><><><><><><><><><><><><><> 664//<><><><><><><><> end screen 0001 <><><><><><><><><> 665//<><><><><><><><><><><><><><><><><><><><><><><><> 666 667//<><><><><><><><><><><><><><><><><><><><><><><><> 668//<><><><><><><><> begin screen 0011 <><><><><><><><> 669//<><><><><><><><><><><><><><><><><><><><><><><><> 670 if(currentScreen == 11){ 671 // " " 672 Tft.drawString("MEGA 2560",00,5,4,BLUE); 673 Tft.drawString("SETTINGS",10,50,4,YELLOW); 674 Tft.drawString("Brightness", 80,130, 3, BLUE); 675 Tft.drawString("Contrast", 05, 195, 3, GREEN); 676 Tft.drawString("Timeout", 10, 260, 3, GREEN); 677 Tft.drawString("<", 0, 160, 3, GREEN); // back button 678} 679 680//<><><><><><><><><><><><><><><><><><><><><><><><> 681//<><><><><><><><> end screen 0011 <><><><><><><><><> 682//<><><><><><><><><><><><><><><><><><><><><><><><> 683 684//<><><><><><><><><><><><><><><><><><><><><><><><> 685//<><><><><><><><> begin screen 0021 <><><><><><><><> 686//<><><><><><><><><><><><><><><><><><><><><><><><> 687 if(currentScreen == 21){ 688 // " " 689 Tft.drawString("MEGA 2560",00,5,4,BLUE); 690 Tft.drawString("SENSORS",10,50,4,YELLOW); 691 Tft.drawString("PIR Array", 80,130, 3, BLUE); 692 Tft.drawString("Sound", 05, 195, 3, GREEN); 693 Tft.drawString("Head Position", 10, 260, 3, GREEN); 694 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 695 Tft.drawString("<", 0, 160, 3, GREEN); // back button 696} 697//<><><><><><><><><><><><><><><><><><><><><><><><> 698//<><><><><><><><> end screen 0021 <><><><><><><><><> 699//<><><><><><><><><><><><><><><><><><><><><><><><> 700 701//<><><><><><><><><><><><><><><><><><><><><><><><> 702//<><><><><><><><> begin screen 0121 <><><><><><><><> 703//<><><><><><><><><><><><><><><><><><><><><><><><> 704 if(currentScreen == 121){ 705 // " " 706 Tft.drawString("PIR",0,5,4,BLUE); 707 Tft.drawString("ARRAY",10,50,4,YELLOW); 708 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 709 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 710 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 711 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 712 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 713 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 714 Tft.drawString("<", 0, 160, 3, GREEN); // back button 715} 716//<><><><><><><><><><><><><><><><><><><><><><><><> 717//<><><><><><><><> end screen 0121 <><><><><><><><><> 718//<><><><><><><><><><><><><><><><><><><><><><><><> 719 720//<><><><><><><><><><><><><><><><><><><><><><><><> 721//<><><><><><><><> begin screen 0221 <><><><><><><><> 722//<><><><><><><><><><><><><><><><><><><><><><><><> 723 if(currentScreen == 221){ 724 // " " 725 Tft.drawString("SOUND",0,5,4,BLUE); 726 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 727 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 728 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 729 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 730 Tft.drawString("<", 0, 160, 3, GREEN); // back button 731} 732//<><><><><><><><><><><><><><><><><><><><><><><><> 733//<><><><><><><><> end screen 0221 <><><><><><><><><> 734//<><><><><><><><><><><><><><><><><><><><><><><><> 735 736//<><><><><><><><><><><><><><><><><><><><><><><><> 737//<><><><><><><><> begin screen 0031 <><><><><><><><> 738//<><><><><><><><><><><><><><><><><><><><><><><><> 739 if(currentScreen == 31){ 740 // " " 741 Tft.drawString("Bluetooth",0,5,4,BLUE); 742 Tft.drawString("Control",10,50,4,YELLOW); 743 Tft.drawString("On", 80,130, 3, BLUE); 744 Tft.drawString("Off", 05, 195, 3, GREEN); 745 Tft.drawString("Monitor", 10, 260, 3, GREEN); 746 Tft.drawString("<", 0, 160, 3, GREEN); // back button 747} 748//<><><><><><><><><><><><><><><><><><><><><><><><> 749//<><><><><><><><> end screen 0031 <><><><><><><><><> 750//<><><><><><><><><><><><><><><><><><><><><><><><> 751 752//<><><><><><><><><><><><><><><><><><><><><><><><> 753//<><><><><><><><> begin screen 0002 <><><><><><><><> 754//<><><><><><><><><><><><><><><><><><><><><><><><> 755 if(currentScreen == 2){ 756 // " " 757 Tft.drawString("Mouth",0,5,4,BLUE); 758 Tft.drawString("Control",10,50,4,YELLOW); 759 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 760 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 761 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 762 Tft.drawString("<", 0, 160, 3, GREEN); // back button 763 } 764//<><><><><><><><><><><><><><><><><><><><><><><><> 765//<><><><><><><><> end screen 0002 <><><><><><><><><> 766//<><><><><><><><><><><><><><><><><><><><><><><><> 767 768 769//<><><><><><><><><><><><><><><><><><><><><><><><> 770//<><><><><><><><> begin screen 0012 <><><><><><><><> 771//<><><><><><><><><><><><><><><><><><><><><><><><> 772 if(currentScreen == 12){ 773 // " " 774 Tft.drawString("Jaw Test",0,5,4,BLUE); 775 Tft.drawString("Operations",10,50,4,YELLOW); 776 Tft.drawString("Open", 80,130, 3, BLUE); 777 Tft.drawString("Close", 05, 195, 3, GREEN); 778 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 779 Tft.drawString("<", 0, 160, 3, GREEN); // back button 780} 781//<><><><><><><><><><><><><><><><><><><><><><><><> 782//<><><><><><><><> end screen 0012 <><><><><><><><><> 783//<><><><><><><><><><><><><><><><><><><><><><><><> 784 785 786//<><><><><><><><><><><><><><><><><><><><><><><><> 787//<><><><><><><><> begin screen 0022 <><><><><><><><> 788//<><><><><><><><><><><><><><><><><><><><><><><><> 789 if(currentScreen == 22){ 790 // " " 791 Tft.drawString("Sound",0,5,4,BLUE); 792 Tft.drawString("Sensors",10,50,4,YELLOW); 793 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 794 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 795 Tft.drawString("Monitor", 10, 260, 3, GREEN); 796 Tft.drawString("<", 0, 160, 3, GREEN); // back button 797} 798//<><><><><><><><><><><><><><><><><><><><><><><><> 799//<><><><><><><><> end screen 0022 <><><><><><><><><> 800//<><><><><><><><><><><><><><><><><><><><><><><><> 801 802 803 804//<><><><><><><><><><><><><><><><><><><><><><><><> 805//<><><><><><><><> begin screen 0122 <><><><><><><><> 806//<><><><><><><><><><><><><><><><><><><><><><><><> 807 if(currentScreen == 122){ 808 // " " 809 Tft.drawString("Alexa Sense",0,5,4,BLUE); 810 Tft.drawString("Operations",10,50,4,YELLOW); 811 Tft.drawString("On", 80,130, 3, BLUE); 812 Tft.drawString("Off", 05, 195, 3, GREEN); 813 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 814 Tft.drawString("<", 0, 160, 3, GREEN); // back button 815} 816//<><><><><><><><><><><><><><><><><><><><><><><><> 817//<><><><><><><><> end screen 0122 <><><><><><><><><> 818//<><><><><><><><><><><><><><><><><><><><><><><><> 819 820//<><><><><><><><><><><><><><><><><><><><><><><><> 821//<><><><><><><><> begin screen 0222 <><><><><><><><> 822//<><><><><><><><><><><><><><><><><><><><><><><><> 823 if(currentScreen == 222){ 824 // " " 825 Tft.drawString("Graves Sense",0,5,4,BLUE); 826 Tft.drawString("Operations",10,50,4,YELLOW); 827 Tft.drawString("On", 80,130, 3, BLUE); 828 Tft.drawString("Off", 05, 195, 3, GREEN); 829 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 830 Tft.drawString("<", 0, 160, 3, GREEN); // back button 831} 832//<><><><><><><><><><><><><><><><><><><><><><><><> 833//<><><><><><><><> end screen 0222 <><><><><><><><><> 834//<><><><><><><><><><><><><><><><><><><><><><><><> 835 836//<><><><><><><><><><><><><><><><><><><><><><><><> 837//<><><><><><><><> begin screen 0032 <><><><><><><><> 838//<><><><><><><><><><><><><><><><><><><><><><><><> 839 if(currentScreen == 32){ 840 // " " 841 Tft.drawString("Sound Sense",0,5,4,BLUE); 842 Tft.drawString("Monitors",10,50,4,YELLOW); 843 Tft.drawString("Alexa", 80,130, 3, BLUE); 844 Tft.drawString("Graves", 05, 195, 3, GREEN); 845 Tft.drawString("<", 0, 160, 3, GREEN); // back button 846} 847//<><><><><><><><><><><><><><><><><><><><><><><><> 848//<><><><><><><><> end screen 0032 <><><><><><><><><> 849//<><><><><><><><><><><><><><><><><><><><><><><><> 850 851//<><><><><><><><><><><><><><><><><><><><><><><><> 852//<><><><><><><><> begin screen 0003 <><><><><><><><> 853//<><><><><><><><><><><><><><><><><><><><><><><><> 854 if(currentScreen == 3){ 855 // " " 856 Tft.drawString("Head Control",0,5,4,BLUE); 857 Tft.drawString("Operations",10,50,4,YELLOW); 858 Tft.drawString("PIR Array", 80,130, 3, BLUE); 859 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 860 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 861 Tft.drawString("<", 0, 160, 3, GREEN); // back button 862} 863//<><><><><><><><><><><><><><><><><><><><><><><><> 864//<><><><><><><><> end screen 0003 <><><><><><><><><> 865//<><><><><><><><><><><><><><><><><><><><><><><><> 866 867//<><><><><><><><><><><><><><><><><><><><><><><><> 868//<><><><><><><><> begin screen 0013 <><><><><><><><> 869//<><><><><><><><><><><><><><><><><><><><><><><><> 870 if(currentScreen == 13){ 871 // " " 872 Tft.drawString("PIR Control",0,5,4,BLUE); 873 Tft.drawString("Operations",10,50,4,YELLOW); 874 Tft.drawString("On", 80,130, 3, BLUE); 875 Tft.drawString("Off", 05, 195, 3, GREEN); 876 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 877 Tft.drawString("<", 0, 160, 3, GREEN); // back button 878} 879//<><><><><><><><><><><><><><><><><><><><><><><><> 880//<><><><><><><><> end screen 0013 <><><><><><><><><> 881//<><><><><><><><><><><><><><><><><><><><><><><><> 882 883//<><><><><><><><><><><><><><><><><><><><><><><><> 884//<><><><><><><><> begin screen 0023 <><><><><><><><> 885//<><><><><><><><><><><><><><><><><><><><><><><><> 886 if(currentScreen == 23){ 887 // " " 888 Tft.drawString("Head Control",0,5,4,BLUE); 889 Tft.drawString("Manual Point",10,50,4,YELLOW); 890 Tft.drawString("Slider", 80,130, 3, BLUE); 891 Tft.drawString("<", 0, 160, 3, GREEN); // back button 892} 893//<><><><><><><><><><><><><><><><><><><><><><><><> 894//<><><><><><><><> end screen 0023 <><><><><><><><><> 895//<><><><><><><><><><><><><><><><><><><><><><><><> 896 897 898////<><><><><><><><><><><><><><><><><><><><><><><><> 899////<><><><><><><><> begin screen lost <><><><><><><><> 900////<><><><><><><><><><><><><><><><><><><><><><><><> 901// else if(currentScreen){ 902// // " " 903// Tft.drawString("Screen not",0,5,3,BLUE); 904// Tft.drawString("found. Please",40,50,3,YELLOW); 905// Tft.drawString("use the back", 80,130, 3, BLUE); 906// Tft.drawString("button to", 05, 195, 3, GREEN); 907// Tft.drawString("return to fun", 10, 260, 3, GREEN); 908// Tft.drawString("<", 0, 160, 3, GREEN); // back button 909//} 910////<><><><><><><><><><><><><><><><><><><><><><><><> 911////<><><><><><><><> end screen lost <><><><><><><><><> 912////<><><><><><><><><><><><><><><><><><><><><><><><> 913 914}// callScreen 915//-------------------------- end callScreen function ------------------------- 916//-------------------------- end callScreen function ------------------------- 917//-------------------------- end callScreen function ------------------------- 918//-------------------------- end callScreen function ------------------------- 919//-------------------------- end callScreen function ------------------------- 920//-------------------------- end callScreen function ------------------------- 921//-------------------------- end callScreen function ------------------------- 922//-------------------------- end callScreen function ------------------------- 923//-------------------------- end callScreen function ------------------------- 924//-------------------------- end callScreen function ------------------------- 925//-------------------------- end callScreen function ------------------------- 926//-------------------------- end callScreen function ------------------------- 927//-------------------------- end callScreen function ------------------------- 928 929 930//**************************************************************************************************** 931//**************************************************************************************************** 932 933 934 935 936 937 938 939//**************************************************************************************************** 940//**************************************************************************************************** 941 942// fin
24102018 Mega code
c_cpp
Screens partially updated. New button groups need adjustment to couple correct screen assignments.
1/* 224102018 3 4gravesmegamaster 5 6graves project 7arduino MEGA 2650 8Master 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17 18sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 19 20 analogue pin speaker + 21 \(yellow signal / (red from speaker) 22 10k Ohm \ wire) / 23 resistor \ / 24 *--------/\\/\\/---------*---------/\\/\\/--------* 25 | \ 10k Ohm | 26 | \ resistor | 27 |(red with white) \ |to arduino ground (black with white) 28to arduino 5v+ -)|- 29 \ 100uF 16v 30 \ capacitor 31 \\ 32 \\ 33 speaker - 34 (black from speaker) 35 36*/ 37//end notes 38//end notes 39//end notes 40//end notes 41//end notes 42//end notes 43 44 45//********************************************************* 46//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 47//********************************************************* 48 49 50//begin declarations 51//begin declarations 52//begin declarations 53//begin declarations 54//begin declarations 55//begin declarations 56//begin declarations 57 58//#include <TFT.h> 59//#include <Servo.h> 60//#include <stdint.h> 61//#include <SD.h> 62#include <TFTv2.h> 63#include <SPI.h> 64#include <SeeedTouchScreen.h> 65//#include <Wire.h> 66 67//const int PIN_SD_CS = 4; // pin of sd card 68 69TouchScreen ts = TouchScreen(XP, YP, XM, YM); 70int zMax; // maximum pressure to detect 71int zMin; // minimum pressure to detect 72 73int buttonPressed; // stores which button was pressed 74unsigned long newButtonTime; // debounce 75unsigned long oldButtonTime; // debounce 76unsigned long buttonTimeDifference; // debounce 77unsigned long debounceTime; // debounce 78int buttonGroup; // sets kinds of buttons on screen 79 80int currentScreen; // identifies current screen by adding x y and z 81int x; // for ones 82int y; // for tens 83int z; // for hundreds 84 85unsigned long backlightTimer; // for backlight timeout 86int backLightState; // status of backlight 1 for on and 0 for off 87unsigned long backlightTimeDifference; 88unsigned long newBacklightTime; 89unsigned long oldBacklightTime; 90 91char incomingMouthByte; 92char outgoingMouthByte; 93int mouthOnOffNew; 94int mouthOnOffOld; 95int mouthOnOffDifference; 96int mouthOnOffAdjusted; // value adjusted by 48 for ascii 97 98char incomingHeadByte; 99char outgoingHeadByte; 100int headOnOffNew; 101int headOnOffOld; 102int headOnOffDifference; 103int headOnOffAdjusted; // value adjusted by 48 for ascii 104 105//end declarations 106//end declarations 107//end declarations 108//end declarations 109//end declarations 110//end declarations 111//end declarations 112//end declarations 113//end declarations 114 115//********************************************************* 116//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 117//********************************************************* 118 119// begin void setup 120// begin void setup 121// begin void setup 122// begin void setup 123// begin void setup 124// begin void setup 125// begin void setup 126// begin void setup 127// begin void setup 128// begin void setup 129// begin void setup 130void setup() { 131Serial.begin(9600); 132Serial1.begin(9600); 133Serial2.begin(9600); 134 oldButtonTime = millis(); 135 newButtonTime = millis(); 136 Tft.TFTinit(); // init TFT library 137 TFT_BL_ON; // turn on the background light 138 backLightState = 1; 139 x = 0; 140 y = 0; 141 z = 0; 142 buttonPressed = 4; 143 buttonGroup = 0; 144 145 incomingHeadByte = 1; 146 outgoingHeadByte = 1; // for a bit more talkative serial data 147 headOnOffNew = 1; // stores head state from serial connection 148 headOnOffOld = 1; // stores head state from serial connection 149 150 151 incomingMouthByte = 0; 152 outgoingMouthByte = 0; // for a bit more talkative serial data 153 mouthOnOffNew = 1; // stores mouth state from serial connection 154 mouthOnOffOld = 1; // stores mouth state from serial connection 155 156 157 //////////////////////////////// 158 //// manually set variables //// 159 //////////////////////////////// 160 161 debounceTime = 1000; // button debounce in milliseconds 162 zMax = 460; // maximum pressure to detect 163 zMin = 100; // minimum pressure to detect 164 165 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 166 167 168 currentScreen = 0; 169 callScreen(); 170 171} //void setup() 172// end void setup 173// end void setup 174// end void setup 175// end void setup 176// end void setup 177// end void setup 178// end void setup 179// end void setup 180 181//********************************************************* 182//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 183//********************************************************* 184 185// begin void loop 186// begin void loop 187// begin void loop 188// begin void loop 189// begin void loop 190// begin void loop 191// begin void loop 192// begin void loop 193// begin void loop 194// begin void loop 195// begin void loop 196// begin void loop 197// begin void loop 198// begin void loop 199 200void loop() { 201 202 tftBacklightTimeout(); // check time and turn off backlight 203 204 if(buttonGroup == 0){ // most regular pages 205 tftButtonGroup0(); // gather information from touch screen touches 206 buttonTimeDifference = newButtonTime - oldButtonTime; 207 if(debounceTime < buttonTimeDifference){ 208 whatScreen(); 209 callScreen(); 210 oldButtonTime = newButtonTime; 211 showStuff(); // serial prints 212 tftDisplay(); // display x y coordinates on tft display 213 } 214 } 215 if(buttonGroup == 1){ // on off buttons 216 tftButtonGroup1(); // gather information from touch screen touches 217 buttonTimeDifference = newButtonTime - oldButtonTime; 218 if(debounceTime < buttonTimeDifference){ 219 whatScreen(); 220 callScreen(); 221 oldButtonTime = newButtonTime; 222 showStuff(); // serial prints 223 tftDisplay(); // display x y coordinates on tft display 224 mouthUnoTxRx(); 225 } 226 } 227 if(buttonGroup == 2){ // head buttons 228 tftButtonGroup2(); // gather information from touch screen touches 229 buttonTimeDifference = newButtonTime - oldButtonTime; 230 if(debounceTime < buttonTimeDifference){ 231 whatScreen(); 232 callScreen(); 233 oldButtonTime = newButtonTime; 234 showStuff(); // serial prints 235 tftDisplay(); // display x y coordinates on tft display 236 headUnoTxRx(); 237 } 238 } 239 240 241} //void loop() 242 243// end of void loop 244// end of void loop 245// end of void loop 246// end of void loop 247// end of void loop 248// end of void loop 249// end of void loop 250// end of void loop 251// end of void loop 252// end of void loop 253// end of void loop 254// end of void loop 255// end of void loop 256// end of void loop 257// end of void loop 258 259//**************************************************************************************************** 260//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 261//**************************************************************************************************** 262///////////////////////////////////////////////////////////////////////////////////////////////////////// 263///////////////////////////////////////// functions /////////////////////////////////////////////////// 264///////////////////////////////////////////////////////////////////////////////////////////////////////// 265//**************************************************************************************************** 266//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 267//**************************************************************************************************** 268 269//--------------------------begin tftBacklightTimeout---------------------------------- 270void tftBacklightTimeout(){ 271 newBacklightTime = millis(); 272 if(backLightState = 0){ 273 backlightTimeDifference = newBacklightTime - oldBacklightTime; 274 if(backlightTimer > backlightTimeDifference){ 275 backlightTimeDifference = newBacklightTime - oldBacklightTime; 276 TFT_BL_ON; // turn on the background light 277 backLightState = 1; 278 oldBacklightTime = millis(); 279 } 280 } 281 if(backLightState = 1){ 282 backlightTimeDifference = newBacklightTime - oldBacklightTime; 283 if(backlightTimer < backlightTimeDifference){ 284 backlightTimeDifference = newBacklightTime - oldBacklightTime; 285 TFT_BL_OFF; // turn off the background light 286 backLightState = 0; 287 oldBacklightTime = millis(); 288 } 289 } 290} 291//--------------------------end tftBacklightTimeout---------------------------------- 292 293//**************************************************************************************************** 294//**************************************************************************************************** 295 296//--------------------------begin tftButtonGroup0---------------------------------- 297//--------------------------begin tftButtonGroup0---------------------------------- 298//--------------------------begin tftButtonGroup0---------------------------------- 299//--------------------------begin tftButtonGroup0---------------------------------- 300int tftButtonGroup0(){ 301 Point p = ts.getPoint(); 302 if(zMin<p.z && p.z<zMax){ 303 TFT_BL_ON; // turn on the background light 304 backLightState = 1; 305 oldBacklightTime = millis(); 306 newButtonTime = millis(); 307 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 308 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 309//Button 1 310 if(75<p.x && p.x<140){ 311 if(100<p.y && p.y<164){ 312 buttonPressed = 1; 313 } 314//Button 2 315 if(164<p.y && p.y<240){ 316 buttonPressed = 2; 317 } 318//Button 3 319 if(240<p.y && p.y<310){ 320 buttonPressed = 3; 321 } 322 } 323 } 324//Button 4 325 if(10<p.x && p.x<75){ 326 if(100<p.y && p.y<240){ 327 buttonPressed = 4; 328 } 329 } 330}//void tftButtonGroup0 331//--------------------------end tftButtonGroup0 code---------------------------------- 332//--------------------------end tftButtonGroup0 code---------------------------------- 333//--------------------------end tftButtonGroup0 code---------------------------------- 334//--------------------------end tftButtonGroup0 code---------------------------------- 335//--------------------------end tftButtonGroup0 code---------------------------------- 336//**************************************************************************************************** 337//**************************************************************************************************** 338 339//--------------------------begin tftButtonGroup1---------------------------------- 340//--------------------------begin tftButtonGroup1---------------------------------- 341//--------------------------begin tftButtonGroup1---------------------------------- 342//--------------------------begin tftButtonGroup1---------------------------------- 343int tftButtonGroup1(){ // for mouth 344buttonPressed = 0; 345 Point p = ts.getPoint(); 346 if(zMin<p.z && p.z<zMax){ 347 TFT_BL_ON; // turn on the background light 348 backLightState = 1; 349 oldBacklightTime = millis(); 350 newButtonTime = millis(); 351 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 352 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 353//Button 1 354 if(75<p.x && p.x<140){ 355 if(100<p.y && p.y<164){ 356 mouthOnOffNew = 1; // on 357 Serial.print("mouthOnOffNew set to "); 358 Serial.println(mouthOnOffNew); 359 } 360//Button 2 361 if(164<p.y && p.y<240){ 362 mouthOnOffNew = 2; // off 363 Serial.print("mouthOnOffNew set to "); 364 Serial.println(mouthOnOffNew); 365 } 366//Button 3 367// if(240<p.y && p.y<310){ 368// mouthOnOffNew = 3; // off 369// Serial.print("mouthOnOffNew set to "); 370// Serial.println(mouthOnOffNew); 371// } 372 } 373 } 374//Button 4 375 if(10<p.x && p.x<75){ 376 if(100<p.y && p.y<240){ 377 buttonPressed = 4; 378 buttonGroup = 0; 379 } 380 } 381}//void tftButtonGroup1 382//--------------------------end tftButtonGroup1 code---------------------------------- 383//--------------------------end tftButtonGroup1 code---------------------------------- 384//--------------------------end tftButtonGroup1 code---------------------------------- 385//--------------------------end tftButtonGroup1 code---------------------------------- 386//--------------------------end tftButtonGroup1 code---------------------------------- 387//**************************************************************************************************** 388//**************************************************************************************************** 389 390//--------------------------begin tftButtonGroup2---------------------------------- 391//--------------------------begin tftButtonGroup2---------------------------------- 392//--------------------------begin tftButtonGroup2---------------------------------- 393//--------------------------begin tftButtonGroup2---------------------------------- 394int tftButtonGroup2(){ // for mouth 395buttonPressed = 0; 396 Point p = ts.getPoint(); 397 if(zMin<p.z && p.z<zMax){ 398 TFT_BL_ON; // turn on the background light 399 backLightState = 1; 400 oldBacklightTime = millis(); 401 newButtonTime = millis(); 402 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 403 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 404//Button 1 405 if(75<p.x && p.x<140){ 406 if(100<p.y && p.y<164){ 407 headOnOffNew = 1; // on 408 Serial.print("headOnOffNew set to "); 409 Serial.println(headOnOffNew); 410 } 411//Button 2 412 if(164<p.y && p.y<240){ 413 headOnOffNew = 2; // off 414 Serial.print("headOnOffNew set to "); 415 Serial.println(headOnOffNew); 416 } 417//Button 3 418// if(240<p.y && p.y<310){ 419// buttonPressed = 3; 420// } 421 } 422 } 423//Button 4 424 if(10<p.x && p.x<75){ 425 if(100<p.y && p.y<240){ 426 buttonPressed = 4; 427 buttonGroup = 0; 428 } 429 } 430}//void tftButtonGroup2 431//--------------------------end tftButtonGroup2 code---------------------------------- 432//--------------------------end tftButtonGroup2 code---------------------------------- 433//--------------------------end tftButtonGroup2 code---------------------------------- 434//--------------------------end tftButtonGroup2 code---------------------------------- 435//--------------------------end tftButtonGroup2 code---------------------------------- 436//**************************************************************************************************** 437//**************************************************************************************************** 438 439//--------------------------begin mouthUnoTxRx---------------------------------- 440 441void mouthUnoTxRx(){ 442 if(mouthOnOffNew != mouthOnOffOld){ 443 Serial.println("starting txrx"); 444 if(mouthOnOffNew == 1){ 445 Serial.println("Starting tx"); 446 Serial1.flush(); 447 Serial1.write('1'); 448 mouthOnOffOld = 1; 449//begin rx 450 Serial.println("Starting rx"); 451 452 delay(10); // tweak delay to accomodate uno 453 454 // use a serial available after flush funtion while or for loop or interrrupt or somethin 455 incomingMouthByte = Serial1.read(); 456 Serial1.flush(); 457 mouthOnOffAdjusted = incomingMouthByte; 458 Serial.print("mouthOnOffAdjusted should be 1: "); 459 Serial.println(mouthOnOffAdjusted); 460 } 461 if(mouthOnOffNew == 2){ 462 Serial.println("Starting tx"); 463 Serial1.flush(); 464 Serial1.write('2'); 465 mouthOnOffOld = 2; 466//begin rx 467 Serial.println("Starting rx"); 468 469 delay(10); // tweak delay to accomodate uno 470 471 incomingMouthByte = Serial1.read(); 472 Serial1.flush(); 473 mouthOnOffAdjusted = incomingMouthByte; 474 Serial.print("mouthOnOffAdjusted should be 2: "); 475 Serial.println(mouthOnOffAdjusted); 476 } 477 if(mouthOnOffNew == 3){ 478 Serial.println("Starting tx"); 479 Serial1.flush(); 480 Serial1.write('3'); 481 mouthOnOffOld = 3; 482//begin rx 483 Serial.println("Starting rx"); 484 485 delay(10); // tweak delay to accomodate uno 486 487 // use a serial available after flush funtion while or for loop or interrrupt or somethin 488 incomingMouthByte = Serial1.read(); 489 Serial1.flush(); 490 mouthOnOffAdjusted = incomingMouthByte; 491 Serial.print("mouthOnOffAdjusted should be 3: "); 492 Serial.println(mouthOnOffAdjusted); 493 } 494 if(mouthOnOffNew == 4){ 495 Serial.println("Starting tx"); 496 Serial1.flush(); 497 Serial1.write('4'); 498 mouthOnOffOld = 4; 499//begin rx 500 Serial.println("Starting rx"); 501 502 delay(10); // tweak delay to accomodate uno 503 504 // use a serial available after flush funtion while or for loop or interrrupt or somethin 505 incomingMouthByte = Serial1.read(); 506 Serial1.flush(); 507 mouthOnOffAdjusted = incomingMouthByte; 508 Serial.print("mouthOnOffAdjusted should be 4: "); 509 Serial.println(mouthOnOffAdjusted); 510 } 511 512 513 else if(mouthOnOffAdjusted <= 1 && 4 >= mouthOnOffAdjusted){ 514 Serial.println("error reply wasn't like expected"); 515 Serial.print("instead, the adjusted reply was"); 516 517 delay(10); // tweak delay to accomodate uno 518 519 incomingMouthByte = Serial1.read(); 520 Serial1.flush(); 521 mouthOnOffAdjusted = incomingMouthByte; 522 Serial.print("mouthOnOffAdjusted: "); 523 Serial.println(mouthOnOffAdjusted); 524 } 525 } 526 else if(mouthOnOffOld = mouthOnOffNew){ 527 } 528 Serial.flush(); 529 Serial1.flush(); 530} 531 532//--------------------------end mouthUnoTxRx -------------------------------------- 533//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 534//--------------------------begin headUnoTxRx---------------------------------- 535 536void headUnoTxRx(){ 537 if(headOnOffNew != headOnOffOld){ 538 Serial.println("starting txrx"); 539 if(headOnOffNew == 1){ 540 Serial.println("Starting tx"); 541 Serial2.flush(); 542 Serial2.write('1'); 543 headOnOffOld = 1; 544//begin rx 545 Serial.println("Starting rx"); 546 547 delay(10); // tweak delay to accomodate uno 548 549 // use a serial available after flush funtion while or for loop or interrrupt or somethin instead of delay 550 incomingHeadByte = Serial2.read(); 551 Serial2.flush(); 552 headOnOffAdjusted = incomingHeadByte; 553 Serial.print("headOnOffAdjusted should be 1: "); 554 Serial.println(headOnOffAdjusted); 555 } 556 if(headOnOffNew == 2){ 557 Serial.println("Starting tx"); 558 Serial2.flush(); 559 Serial2.write('2'); 560 headOnOffOld = 2; 561//begin rx 562 Serial.println("Starting rx"); 563 564 delay(10); // tweak delay to accomodate uno 565 566 incomingHeadByte = Serial2.read(); 567 Serial2.flush(); 568 headOnOffAdjusted = incomingHeadByte; 569 Serial.print("headOnOffAdjusted should be 2: "); 570 Serial.println(headOnOffAdjusted); 571 } 572 else if(headOnOffAdjusted != 1 && headOnOffAdjusted != 2){ 573 Serial.println("error reply wasn't like expected"); 574 Serial.print("instead, the adjusted reply was"); 575 576 delay(10); // tweak delay to accomodate uno 577 578 incomingHeadByte = Serial2.read(); 579 Serial2.flush(); 580 headOnOffAdjusted = incomingHeadByte; 581 Serial.print("headOnOffAdjusted: "); 582 Serial.println(headOnOffAdjusted); 583 } 584 } 585 else if(headOnOffOld = headOnOffNew){ 586 } 587 Serial.flush(); 588 Serial2.flush(); 589} 590 591//--------------------------end headUnoTxRx -------------------------------------- 592//**************************************************************************************************** 593//**************************************************************************************************** 594 595//--------------------------begin tftDisplay code---------------------------------- 596void tftDisplay(){ 597 Point p = ts.getPoint(); 598 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 599 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 600 601 Tft.fillRectangle(70, 100, 60, 30, BLACK); 602 Tft.drawNumber((buttonGroup), 70, 100, 3, GREEN); 603 Tft.fillRectangle(140, 100, 60, 30, BLACK); 604 Tft.drawNumber((mouthOnOffNew), 140, 100, 3, GREEN); 605 Tft.fillRectangle(160, 100, 60, 30, BLACK); 606 Tft.drawNumber((headOnOffNew), 160, 100, 3, GREEN); 607 Tft.fillRectangle(0, 225, 60, 30, BLACK); 608 Tft.drawNumber((p.x), 0, 225, 3, GREEN); 609 Tft.fillRectangle(180, 225, 60, 30, BLACK); 610 Tft.drawNumber((p.y), 180, 225, 3, GREEN); 611 Tft.fillRectangle(100, 225, 60, 30, BLACK); 612 Tft.drawNumber((buttonPressed), 100, 225, 3, GREEN); 613 Tft.fillRectangle(120, 290, 60, 30, BLACK); 614 Tft.drawNumber((currentScreen), 120, 290, 3, GREEN); 615 616 617}// void tftDisplay 618//--------------------------end tftDisplay code------------------------------------ 619 620//**************************************************************************************************** 621//**************************************************************************************************** 622 623//-------------------------- begin mouth on off function -------------------------- 624//-------------------------- end mouth on off function -------------------------- 625 626//**************************************************************************************************** 627//**************************************************************************************************** 628 629//-------------------------- begin head on off function -------------------------- 630//-------------------------- end head on off function ------------------------- 631 632//**************************************************************************************************** 633//**************************************************************************************************** 634 635//-------------------------- begin serial display function -------------------------- 636void showStuff(){ 637 Serial.println("------/ last update /-------"); 638// Serial.println("------begin display-------"); 639 Serial.print("buttonPressed "); 640 Serial.println(buttonPressed); 641 Serial.print("x "); 642 Serial.println(x); 643 Serial.print("y "); 644 Serial.println(y); 645 Serial.print("z "); 646 Serial.println(z); 647 Serial.print("currentScreen "); 648 Serial.println(currentScreen); 649// Serial.println("-------end display--------"); 650 Serial.println(""); 651 Serial.println(""); 652 Serial.println(""); 653 } 654//-------------------------- end serial display function ------------------------- 655 656 657//**************************************************************************************************** 658//**************************************************************************************************** 659 660//--------------------------- Primary screen maps -------------------------------- 661/* 662******** 663updates needed 664******** 6651 ditch the contrast 6662 ditch the brightness 6673 setup screen timeout 668 669 670 671 672screen 0000 A)Central Command 673 674 screen 0001 a)motor controls 675 676 screen 0001 b) Touch Screen Timeout 677 screen 0011 -longer 678 screen 0011 -shorter 679 screen 0011 -reset 680 681 screen 0001 c)sensor monitors 682 screen 0021 -head reports 683 screen 0121 *report pir detection 684 screen 0121 *report pot position 685 screen 0021 -mouth reports 686 screen 0221 *graves sense 687 screen 0221 *echo sense 688 screen 0221 *report mouth servo position 689// screen 0221 *adjust sensitivity? 690 691screen 0000 B)Mouth Control 692 693 screen 0002 a)test button 694 screen 0012 -open 695 screen 0012 -close 696 697 screen 0002 b)sound sensors on/off 698 699 screen 0022 -echo sense 700 screen 0122 *on 701 screen 0122 *off 702 screen 0122 *monitor sensor 703 704 screen 0022 -graves sense 705 screen 0222 *on 706 screen 0222 *off 707 screen 0222 *monitor sensors 708 709 screen 0002 c)sound sensor status 710 screen 0032 -echo 711 screen 0032 -graves 712 713screen 0000 C)Head Control 714 screen 0003 a)head motor on/off 715 screen 0013 -on 716 screen 0013 -off 717 screen 0003 b)manual point 718 screen 0023 -slider 719 ---/\ 720ew screens/\\--- 721 722 ---\\/old screens\\/--- 723 screen 0000 A)Home 724 screen 0001 a)settings 725 screen 0011 -brightness 726 screen 0011 -contrast 727 screen 0011 -screen lock time out 728 screen 0001 b)sensor monitors 729 screen 0021 -pir 730 screen 0121 *report pir detection 731 screen 0021 -sound 732 screen 0221 *sense echo sound 733 screen 0221 *sense graves sound 734 screen 0221 *report mouth servo position 735 screen 0221 *adjust sensitivity? 736 screen 0021 -head potentiometer 737 screen 0021 -bluetooth 738 screen 0001 c)bluetooth 739 screen 0031 -on 740 screen 0031 -off 741 screen 0031 -monitor 742screen 0000 B)Mouth Control 743 screen 0002 a)test button 744 screen 0012 -open 745 screen 0012 -close 746 screen 0012 -push button chicken switch 747 screen 0002 b)sound sensors on/off 748 screen 0022 -echo sense 749 screen 0122 *on 750 screen 0122 *off 751 screen 0122 *monitor sensor 752 screen 0022 -graves sense 753 screen 0222 *on 754 screen 0222 *off 755 screen 0222 *monitor sensors 756 screen 0002 c)sound sensor status 757 screen 0032 -echo 758 screen 0032 -graves 759screen 0000 C)Head Control 760 screen 0003 a)pir on/off 761 screen 0013 -on 762 screen 0013 -off 763 screen 0013 -sensor 764 screen 0003 b)manual point 765 screen 0023 -slider 766*/ 767//**************************************************************************************************** 768//**************************************************************************************************** 769//-------------------------- begin whatScreen function ------------------------- 770//-------------------------- begin whatScreen function ------------------------- 771//-------------------------- begin whatScreen function ------------------------- 772//-------------------------- begin whatScreen function ------------------------- 773 774int whatScreen(){ 775 if(x == 0){ 776 if(buttonPressed == 1){ 777 x = x + 1; 778 Serial.println("x + 1"); 779 } 780 if(buttonPressed == 2){ 781 x = x + 2; 782 Serial.println("x + 2"); 783 } 784 if(buttonPressed == 3){ 785 x = x + 3; 786 Serial.println("x + 3"); 787 } 788 if(buttonPressed == 4){ 789 x = 0; 790 Serial.println("x = 0"); 791 } 792 if(buttonPressed == 5){ 793 x = 0; 794 y = 0; 795 z = 0; 796 Serial.println("xyz all 0"); 797 } 798 } 799 else if(x >> 0){ 800 if(y == 0){ 801 if(buttonPressed == 1){ 802 y = y + 10; 803 Serial.println("y + 10"); 804 } 805 if(buttonPressed == 2){ 806 y = y + 20; 807 Serial.println("y + 20"); 808 } 809 if(buttonPressed == 3){ 810 y = y + 30; 811 Serial.println("y + 30"); 812 } 813 if(buttonPressed == 4){ 814 x = 0; 815 Serial.println("x = 0"); 816 } 817 if(buttonPressed == 5){ 818 x = 0; 819 y = 0; 820 z = 0; 821 Serial.println("xyz all 0"); 822 } 823 } 824 else if (y >> 0){ 825 if(buttonPressed == 1){ 826 z = z + 100; 827 Serial.println("z + 100"); 828 } 829 if(buttonPressed == 2){ 830 z = z + 200; 831 Serial.println("z + 200"); 832 } 833 if(buttonPressed == 3){ 834 z = z + 300; 835 Serial.println("z + 300"); 836 } 837 if(buttonPressed == 4){ 838 if(z == 0){ 839 y = 0; 840 Serial.println("y = 0"); 841 } 842 else if(z >> 0){ 843 z = 0; 844 Serial.println("z = 0"); 845 } 846 } 847 if(buttonPressed == 5){ 848 x = 0; 849 y = 0; 850 z = 0; 851 Serial.println("xyz all 0"); 852 } 853 }//y>0 854 }//x>0 855 currentScreen = z+y+x; 856 857 858//================button group exceptions================ 859//================button group exceptions================ 860 if(currentScreen == 122){ 861 buttonGroup=1; 862 } 863 if(currentScreen == 222){ 864 buttonGroup=1; 865 } 866 if(currentScreen == 23){ 867 buttonGroup=2; 868 } 869//================button group exceptions================ 870//================button group exceptions================ 871 872} 873//-------------------------- end whatScreen function ------------------------- 874//-------------------------- end whatScreen function ------------------------- 875//-------------------------- end whatScreen function ------------------------- 876//-------------------------- end whatScreen function ------------------------- 877//-------------------------- end whatScreen function ------------------------- 878 879//**************************************************************************************************** 880//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 881//**************************************************************************************************** 882//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 883//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 884//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 885//**************************************************************************************************** 886//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 887//**************************************************************************************************** 888 889//-------------------------- begin callScreen function ------------------------- 890//-------------------------- begin callScreen function ------------------------- 891//-------------------------- begin callScreen function ------------------------- 892//-------------------------- begin callScreen function ------------------------- 893//-------------------------- begin callScreen function ------------------------- 894//-------------------------- begin callScreen function ------------------------- 895//-------------------------- begin callScreen function ------------------------- 896//-------------------------- begin callScreen function ------------------------- 897//-------------------------- begin callScreen function ------------------------- 898//-------------------------- begin callScreen function ------------------------- 899//-------------------------- begin callScreen function ------------------------- 900 901int callScreen(){ 902 Tft.fillRectangle(0, 0, 240, 320, BLACK); 903 904//<><><><><><><><><><><><><><><><><><><><><><><><> 905//<><><><><><><><> begin screen 0000 master <><><><><><><><> 906//<><><><><><><><><><><><><><><><><><><><><><><><> 907if(currentScreen == 0){ 908 // " " 909 Tft.drawString("GRAVES",0,5,4, GREEN); 910 Tft.drawString("INTERFACE",10,50,4,GREEN); 911 Tft.drawString("Main Controls", 80,130, 3, GREEN); 912 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 913 Tft.drawString("Head Control", 10, 260, 3, GREEN); 914} 915//<><><><><><><><><><><><><><><><><><><><><><><><> 916//<><><><><><><><> end screen 0000 master <><><><><><><><><> 917//<><><><><><><><><><><><><><><><><><><><><><><><> 918 919//<><><><><><><><><><><><><><><><><><><><><><><><> 920//<><><><><><><><> begin screen 0001 <><><><><><><><> 921//<><><><><><><><><><><><><><><><><><><><><><><><> 922 if(currentScreen == 1){ 923 // " " 924 Tft.drawString("SETTINGS",00,5,4,BLUE); 925 Tft.drawString("FOR THINGS",00,50,4,BLUE); 926 Tft.drawString("Motors Power", 10,130, 3, BLUE); 927 Tft.drawString("Sensors", 20, 195, 3, BLUE); 928 Tft.drawString("Light Timeout", 00, 260, 3, BLUE); 929 Tft.drawString("<", 0, 160, 3, GREEN); // back button 930} 931//<><><><><><><><><><><><><><><><><><><><><><><><> 932//<><><><><><><><> end screen 0001 <><><><><><><><><> 933//<><><><><><><><><><><><><><><><><><><><><><><><> 934 935//<><><><><><><><><><><><><><><><><><><><><><><><> 936//<><><><><><><><> begin screen 0011 <><><><><><><><> 937//<><><><><><><><><><><><><><><><><><><><><><><><> 938 if(currentScreen == 11){ 939 // " " 940 Tft.drawString("BACKLIGHT",00,5,4,BLUE); 941 Tft.drawString("TIME OUT",10,50,4,YELLOW); 942 Tft.drawString("Increase", 80,130, 3, BLUE); 943 Tft.drawString("Decrease", 05, 195, 3, GREEN); 944 Tft.drawString("Reset", 10, 260, 3, GREEN); 945 Tft.drawString("<", 0, 160, 3, GREEN); // back button 946} 947 948//<><><><><><><><><><><><><><><><><><><><><><><><> 949//<><><><><><><><> end screen 0011 <><><><><><><><><> 950//<><><><><><><><><><><><><><><><><><><><><><><><> 951 952//<><><><><><><><><><><><><><><><><><><><><><><><> 953//<><><><><><><><> begin screen 0021 <><><><><><><><> 954//<><><><><><><><><><><><><><><><><><><><><><><><> 955 if(currentScreen == 21){ 956 // " " 957 Tft.drawString("INCOMING",00,5,4,BLUE); 958 Tft.drawString("SENSOR DATA",10,50,4,YELLOW); 959 Tft.drawString("Head Sensors", 80,130, 3, BLUE); 960 Tft.drawString("Mouth Sensors", 05, 195, 3, GREEN); 961// Tft.drawString("Head Position", 10, 260, 3, GREEN); 962// Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 963 Tft.drawString("<", 0, 160, 3, GREEN); // back button 964} 965//<><><><><><><><><><><><><><><><><><><><><><><><> 966//<><><><><><><><> end screen 0021 <><><><><><><><><> 967//<><><><><><><><><><><><><><><><><><><><><><><><> 968 969//<><><><><><><><><><><><><><><><><><><><><><><><> 970//<><><><><><><><> begin screen 0121 <><><><><><><><> 971//<><><><><><><><><><><><><><><><><><><><><><><><> 972 if(currentScreen == 121){ 973 // " " 974 Tft.drawString("HEAD",0,5,4,BLUE); 975 Tft.drawString("SENSORS",10,50,4,YELLOW); 976 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 977 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 978 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 979 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 980 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 981 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 982 Tft.drawString("<", 0, 160, 3, GREEN); // back button 983} 984//<><><><><><><><><><><><><><><><><><><><><><><><> 985//<><><><><><><><> end screen 0121 <><><><><><><><><> 986//<><><><><><><><><><><><><><><><><><><><><><><><> 987 988//<><><><><><><><><><><><><><><><><><><><><><><><> 989//<><><><><><><><> begin screen 0221 <><><><><><><><> 990//<><><><><><><><><><><><><><><><><><><><><><><><> 991 if(currentScreen == 221){ 992 // " " 993 Tft.drawString("MOUTH",0,5,4,BLUE); 994 Tft.drawString("SENSORS",10,50,4,YELLOW); 995 Tft.drawString("Echo Sense", 05, 195, 3, GREEN); 996 Tft.drawString("Servo Position", 10, 260, 3, GREEN); 997 Tft.drawString("<", 0, 160, 3, GREEN); // back button 998} 999//<><><><><><><><><><><><><><><><><><><><><><><><> 1000//<><><><><><><><> end screen 0221 <><><><><><><><><> 1001//<><><><><><><><><><><><><><><><><><><><><><><><> 1002 1003//<><><><><><><><><><><><><><><><><><><><><><><><> 1004//<><><><><><><><> begin screen 0031 <><><><><><><><> 1005//<><><><><><><><><><><><><><><><><><><><><><><><> 1006 if(currentScreen == 31){ 1007 // " " 1008 Tft.drawString("Bluetooth",0,5,4,BLUE); 1009 Tft.drawString("Control",10,50,4,YELLOW); 1010 Tft.drawString("On", 80,130, 3, BLUE); 1011 Tft.drawString("Off", 05, 195, 3, GREEN); 1012 Tft.drawString("Monitor", 10, 260, 3, GREEN); 1013 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1014} 1015//<><><><><><><><><><><><><><><><><><><><><><><><> 1016//<><><><><><><><> end screen 0031 <><><><><><><><><> 1017//<><><><><><><><><><><><><><><><><><><><><><><><> 1018 1019//<><><><><><><><><><><><><><><><><><><><><><><><> 1020//<><><><><><><><> begin screen 0002 <><><><><><><><> 1021//<><><><><><><><><><><><><><><><><><><><><><><><> 1022 if(currentScreen == 2){ 1023 // " " 1024 Tft.drawString("Mouth",0,5,4,BLUE); 1025 Tft.drawString("Control",10,50,4,YELLOW); 1026 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 1027 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 1028 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1029 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1030 } 1031//<><><><><><><><><><><><><><><><><><><><><><><><> 1032//<><><><><><><><> end screen 0002 <><><><><><><><><> 1033//<><><><><><><><><><><><><><><><><><><><><><><><> 1034 1035 1036//<><><><><><><><><><><><><><><><><><><><><><><><> 1037//<><><><><><><><> begin screen 0012 <><><><><><><><> 1038//<><><><><><><><><><><><><><><><><><><><><><><><> 1039 if(currentScreen == 12){ 1040 // " " 1041 Tft.drawString("JAW TEST",0,5,4,BLUE); 1042 Tft.drawString("OPERATION",10,50,4,YELLOW); 1043 Tft.drawString("Open", 80,130, 3, BLUE); 1044 Tft.drawString("Close", 05, 195, 3, GREEN); 1045// Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 1046 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1047} 1048//<><><><><><><><><><><><><><><><><><><><><><><><> 1049//<><><><><><><><> end screen 0012 <><><><><><><><><> 1050//<><><><><><><><><><><><><><><><><><><><><><><><> 1051 1052 1053//<><><><><><><><><><><><><><><><><><><><><><><><> 1054//<><><><><><><><> begin screen 0022 <><><><><><><><> 1055//<><><><><><><><><><><><><><><><><><><><><><><><> 1056 if(currentScreen == 22){ 1057 // " " 1058 Tft.drawString("SOUND SENSOR",0,5,4,BLUE); 1059 Tft.drawString("SELECTION",10,50,4,YELLOW); 1060 Tft.drawString("echo Sense", 80,130, 3, BLUE); 1061 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 1062 Tft.drawString("Monitor Both", 10, 260, 3, GREEN); 1063 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1064} 1065//<><><><><><><><><><><><><><><><><><><><><><><><> 1066//<><><><><><><><> end screen 0022 <><><><><><><><><> 1067//<><><><><><><><><><><><><><><><><><><><><><><><> 1068 1069 1070 1071//<><><><><><><><><><><><><><><><><><><><><><><><> 1072//<><><><><><><><> begin screen 0122 <><><><><><><><> 1073//<><><><><><><><><><><><><><><><><><><><><><><><> 1074 if(currentScreen == 122){ 1075 // " " 1076 Tft.drawString("ECHO SENSOR",0,5,4,BLUE); 1077 Tft.drawString("MONITOR",10,50,4,YELLOW); 1078 Tft.drawString("", 120, 130, 3, GREEN); 1079 Tft.drawString("", 115, 195, 3, RED); 1080 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1081 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1082} 1083//<><><><><><><><><><><><><><><><><><><><><><><><> 1084//<><><><><><><><> end screen 0122 <><><><><><><><><> 1085//<><><><><><><><><><><><><><><><><><><><><><><><> 1086 1087//<><><><><><><><><><><><><><><><><><><><><><><><> 1088//<><><><><><><><> begin screen 0222 <><><><><><><><> 1089//<><><><><><><><><><><><><><><><><><><><><><><><> 1090 if(currentScreen == 222){ 1091 // " " 1092 Tft.drawString("GRAVES SENSOR",0,5,4,BLUE); 1093 Tft.drawString("MONITOR",10,50,4,YELLOW); 1094 Tft.drawString("", 120, 130, 3, GREEN); 1095 Tft.drawString("", 115, 195, 3, RED); 1096 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1097 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1098} 1099//<><><><><><><><><><><><><><><><><><><><><><><><> 1100//<><><><><><><><> end screen 0222 <><><><><><><><><> 1101//<><><><><><><><><><><><><><><><><><><><><><><><> 1102 1103//<><><><><><><><><><><><><><><><><><><><><><><><> 1104//<><><><><><><><> begin screen 0032 <><><><><><><><> 1105//<><><><><><><><><><><><><><><><><><><><><><><><> 1106 if(currentScreen == 32){ 1107 // " " 1108 Tft.drawString("ECHO & GRAVES",0,5,4,BLUE); 1109 Tft.drawString("SENSORS",10,50,4,YELLOW); 1110 Tft.drawString("echo", 80,130, 3, BLUE); 1111 Tft.drawString("Graves", 05, 195, 3, GREEN); 1112 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1113} 1114//<><><><><><><><><><><><><><><><><><><><><><><><> 1115//<><><><><><><><> end screen 0032 <><><><><><><><><> 1116//<><><><><><><><><><><><><><><><><><><><><><><><> 1117 1118//<><><><><><><><><><><><><><><><><><><><><><><><> 1119//<><><><><><><><> begin screen 0003 <><><><><><><><> 1120//<><><><><><><><><><><><><><><><><><><><><><><><> 1121 if(currentScreen == 3){ 1122 // " " 1123 Tft.drawString("Head Control",0,5,4,BLUE); 1124 Tft.drawString("Operations",10,50,4,YELLOW); 1125 Tft.drawString("PIR Array", 80,130, 3, BLUE); 1126 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 1127 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 1128 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1129} 1130//<><><><><><><><><><><><><><><><><><><><><><><><> 1131//<><><><><><><><> end screen 0003 <><><><><><><><><> 1132//<><><><><><><><><><><><><><><><><><><><><><><><> 1133 1134//<><><><><><><><><><><><><><><><><><><><><><><><> 1135//<><><><><><><><> begin screen 0013 <><><><><><><><> 1136//<><><><><><><><><><><><><><><><><><><><><><><><> 1137 if(currentScreen == 13){ 1138 // " " 1139 Tft.drawString("HEAD MOTOR",0,5,4,BLUE); 1140 Tft.drawString("CONTROL",10,50,4,YELLOW); 1141 Tft.drawString("On", 80,130, 3, BLUE); 1142 Tft.drawString("Off", 05, 195, 3, GREEN); 1143 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 1144 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1145} 1146//<><><><><><><><><><><><><><><><><><><><><><><><> 1147//<><><><><><><><> end screen 0013 <><><><><><><><><> 1148//<><><><><><><><><><><><><><><><><><><><><><><><> 1149 1150//<><><><><><><><><><><><><><><><><><><><><><><><> 1151//<><><><><><><><> begin screen 0023 <><><><><><><><> 1152//<><><><><><><><><><><><><><><><><><><><><><><><> 1153 if(currentScreen == 23){ 1154 // " " 1155 Tft.drawString("GRAVES HEAD",0,5,3,BLUE); 1156 Tft.drawString("POINTER",10,50,3,YELLOW); 1157 Tft.drawString("Left", 120, 130, 3, GREEN); 1158 Tft.drawString("Right", 115, 195, 3, RED); 1159 Tft.drawString("Center", 10, 260, 3, GREEN); 1160 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1161} 1162//<><><><><><><><><><><><><><><><><><><><><><><><> 1163//<><><><><><><><> end screen 0023 <><><><><><><><><> 1164//<><><><><><><><><><><><><><><><><><><><><><><><> 1165 1166 1167//<><><><><><><><><><><><><><><><><><><><><><><><> 1168//<><><><><><><><> begin screen 0422 <><><><><><><><> 1169//<><><><><><><><><><><><><><><><><><><><><><><><> 1170 if(currentScreen == 422){ 1171 // " " 1172 Tft.drawString("Command Sent",0,5,3,BLUE); 1173 Tft.drawString("Press Back to",0,55,3,YELLOW); 1174 Tft.drawString("Contiue", 50,105, 3, BLUE); 1175 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1176} 1177//<><><><><><><><><><><><><><><><><><><><><><><><> 1178//<><><><><><><><> end screen 0422 <><><><><><><><><> 1179//<><><><><><><><><><><><><><><><><><><><><><><><> 1180 1181 1182////<><><><><><><><><><><><><><><><><><><><><><><><> 1183////<><><><><><><><> begin screen lost <><><><><><><><> 1184////<><><><><><><><><><><><><><><><><><><><><><><><> 1185// else if(currentScreen){ 1186// // " " 1187// Tft.drawString("Screen not",0,5,3,BLUE); 1188// Tft.drawString("found. Please",40,50,3,YELLOW); 1189// Tft.drawString("use the back", 80,130, 3, BLUE); 1190// Tft.drawString("button to", 05, 195, 3, GREEN); 1191// Tft.drawString("return to fun", 10, 260, 3, GREEN); 1192// Tft.drawString("<", 0, 160, 3, GREEN); // back button 1193//} 1194////<><><><><><><><><><><><><><><><><><><><><><><><> 1195////<><><><><><><><> end screen lost <><><><><><><><><> 1196////<><><><><><><><><><><><><><><><><><><><><><><><> 1197 1198}// callScreen 1199//-------------------------- end callScreen function ------------------------- 1200//-------------------------- end callScreen function ------------------------- 1201//-------------------------- end callScreen function ------------------------- 1202//-------------------------- end callScreen function ------------------------- 1203//-------------------------- end callScreen function ------------------------- 1204//-------------------------- end callScreen function ------------------------- 1205//-------------------------- end callScreen function ------------------------- 1206//-------------------------- end callScreen function ------------------------- 1207//-------------------------- end callScreen function ------------------------- 1208//-------------------------- end callScreen function ------------------------- 1209//-------------------------- end callScreen function ------------------------- 1210//-------------------------- end callScreen function ------------------------- 1211//-------------------------- end callScreen function ------------------------- 1212 1213 1214//**************************************************************************************************** 1215//**************************************************************************************************** 1216 1217 1218 1219 1220 1221 1222 1223//**************************************************************************************************** 1224//**************************************************************************************************** 1225 1226// fin
22102018 graves mega master
c_cpp
code for arduino 2560 contols tft along with sending on off commands to head uno and mouth uno
1/* 2last edit monday oct 22 2018 3 4gravesmegamaster 5 6graves project 7arduino MEGA 2650 8Master 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17 18sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 19 20 analogue pin speaker + 21 \(yellow signal / (red from speaker) 22 \ wire) / 23 \ / 24 *--------[=]-----------*---------[=]----------* 25 | resistor \ resistor | 26 | \ | 27 |(red with white) \ |to arduino ground (black with white) 28to arduino 5v+ speaker - 29 (black from speaker) 30 31*/ 32//end notes 33//end notes 34//end notes 35//end notes 36//end notes 37//end notes 38 39 40//********************************************************* 41//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 42//********************************************************* 43 44 45//begin declarations 46//begin declarations 47//begin declarations 48//begin declarations 49//begin declarations 50//begin declarations 51//begin declarations 52 53//#include <TFT.h> 54//#include <Servo.h> 55//#include <stdint.h> 56//#include <SD.h> 57#include <TFTv2.h> 58#include <SPI.h> 59#include <SeeedTouchScreen.h> 60//#include <Wire.h> 61 62//const int PIN_SD_CS = 4; // pin of sd card 63 64TouchScreen ts = TouchScreen(XP, YP, XM, YM); 65int zMax; // maximum pressure to detect 66int zMin; // minimum pressure to detect 67 68int buttonPressed; // stores which button was pressed 69unsigned long newButtonTime; // debounce 70unsigned long oldButtonTime; // debounce 71unsigned long buttonTimeDifference; // debounce 72unsigned long debounceTime; // debounce 73int buttonGroup; // sets kinds of buttons on screen 74 75int currentScreen; // identifies current screen by adding x y and z 76int x; // for ones 77int y; // for tens 78int z; // for hundreds 79 80unsigned long backlightTimer; // for backlight timeout 81int backLightState; // status of backlight 1 for on and 0 for off 82unsigned long backlightTimeDifference; 83unsigned long newBacklightTime; 84unsigned long oldBacklightTime; 85 86char incomingMouthByte; 87char outgoingMouthByte; 88int mouthOnOffNew; 89int mouthOnOffOld; 90int mouthOnOffDifference; 91int mouthOnOffAdjusted; // value adjusted by 48 for ascii 92 93char incomingHeadByte; 94char outgoingHeadByte; 95int headOnOffNew; 96int headOnOffOld; 97int headOnOffDifference; 98int headOnOffAdjusted; // value adjusted by 48 for ascii 99 100//end declarations 101//end declarations 102//end declarations 103//end declarations 104//end declarations 105//end declarations 106//end declarations 107//end declarations 108//end declarations 109 110//********************************************************* 111//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 112//********************************************************* 113 114// begin void setup 115// begin void setup 116// begin void setup 117// begin void setup 118// begin void setup 119// begin void setup 120// begin void setup 121// begin void setup 122// begin void setup 123// begin void setup 124// begin void setup 125void setup() { 126Serial.begin(9600); 127Serial1.begin(9600); 128Serial2.begin(9600); 129 oldButtonTime = millis(); 130 newButtonTime = millis(); 131 Tft.TFTinit(); // init TFT library 132 TFT_BL_ON; // turn on the background light 133 backLightState = 1; 134 x = 0; 135 y = 0; 136 z = 0; 137 buttonPressed = 4; 138 buttonGroup = 0; 139 140 incomingHeadByte = 1; 141 outgoingHeadByte = 1; // for a bit more talkative serial data 142 headOnOffNew = 1; // stores head state from serial connection 143 headOnOffOld = 1; // stores head state from serial connection 144 145 146 incomingMouthByte = 0; 147 outgoingMouthByte = 0; // for a bit more talkative serial data 148 mouthOnOffNew = 1; // stores mouth state from serial connection 149 mouthOnOffOld = 1; // stores mouth state from serial connection 150 151 152 //////////////////////////////// 153 //// manually set variables //// 154 //////////////////////////////// 155 156 debounceTime = 1000; // button debounce in milliseconds 157 zMax = 460; // maximum pressure to detect 158 zMin = 100; // minimum pressure to detect 159 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 160 161 162 currentScreen = 0; 163 callScreen(); 164 165} //void setup() 166// end void setup 167// end void setup 168// end void setup 169// end void setup 170// end void setup 171// end void setup 172// end void setup 173// end void setup 174 175//********************************************************* 176//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 177//********************************************************* 178 179// begin void loop 180// begin void loop 181// begin void loop 182// begin void loop 183// begin void loop 184// begin void loop 185// begin void loop 186// begin void loop 187// begin void loop 188// begin void loop 189// begin void loop 190// begin void loop 191// begin void loop 192// begin void loop 193 194void loop() { 195 196 tftBacklightTimeout(); // check time and turn off backlight 197 198 if(buttonGroup == 0){ // most regular pages 199 tftButtonGroup0(); // gather information from touch screen touches 200 buttonTimeDifference = newButtonTime - oldButtonTime; 201 if(debounceTime < buttonTimeDifference){ 202 whatScreen(); 203 callScreen(); 204 oldButtonTime = newButtonTime; 205 showStuff(); // serial prints 206 tftDisplay(); // display x y coordinates on tft display 207 } 208 } 209 if(buttonGroup == 1){ // on off buttons 210 tftButtonGroup1(); // gather information from touch screen touches 211 buttonTimeDifference = newButtonTime - oldButtonTime; 212 if(debounceTime < buttonTimeDifference){ 213 whatScreen(); 214 callScreen(); 215 oldButtonTime = newButtonTime; 216 showStuff(); // serial prints 217 tftDisplay(); // display x y coordinates on tft display 218 mouthUnoTxRx(); 219 } 220 } 221 if(buttonGroup == 2){ // head buttons 222 tftButtonGroup2(); // gather information from touch screen touches 223 buttonTimeDifference = newButtonTime - oldButtonTime; 224 if(debounceTime < buttonTimeDifference){ 225 whatScreen(); 226 callScreen(); 227 oldButtonTime = newButtonTime; 228 showStuff(); // serial prints 229 tftDisplay(); // display x y coordinates on tft display 230 headUnoTxRx(); 231 } 232 } 233 234 235} //void loop() 236 237// end of void loop 238// end of void loop 239// end of void loop 240// end of void loop 241// end of void loop 242// end of void loop 243// end of void loop 244// end of void loop 245// end of void loop 246// end of void loop 247// end of void loop 248// end of void loop 249// end of void loop 250// end of void loop 251// end of void loop 252 253//**************************************************************************************************** 254//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 255//**************************************************************************************************** 256///////////////////////////////////////////////////////////////////////////////////////////////////////// 257///////////////////////////////////////// functions /////////////////////////////////////////////////// 258///////////////////////////////////////////////////////////////////////////////////////////////////////// 259//**************************************************************************************************** 260//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 261//**************************************************************************************************** 262 263//--------------------------begin tftBacklightTimeout---------------------------------- 264void tftBacklightTimeout(){ 265 newBacklightTime = millis(); 266 if(backLightState = 0){ 267 backlightTimeDifference = newBacklightTime - oldBacklightTime; 268 if(backlightTimer > backlightTimeDifference){ 269 backlightTimeDifference = newBacklightTime - oldBacklightTime; 270 TFT_BL_ON; // turn on the background light 271 backLightState = 1; 272 oldBacklightTime = millis(); 273 } 274 } 275 if(backLightState = 1){ 276 backlightTimeDifference = newBacklightTime - oldBacklightTime; 277 if(backlightTimer < backlightTimeDifference){ 278 backlightTimeDifference = newBacklightTime - oldBacklightTime; 279 TFT_BL_OFF; // turn off the background light 280 backLightState = 0; 281 oldBacklightTime = millis(); 282 } 283 } 284} 285//--------------------------end tftBacklightTimeout---------------------------------- 286 287//**************************************************************************************************** 288//**************************************************************************************************** 289 290//--------------------------begin tftButtonGroup0---------------------------------- 291//--------------------------begin tftButtonGroup0---------------------------------- 292//--------------------------begin tftButtonGroup0---------------------------------- 293//--------------------------begin tftButtonGroup0---------------------------------- 294int tftButtonGroup0(){ 295 Point p = ts.getPoint(); 296 if(zMin<p.z && p.z<zMax){ 297 TFT_BL_ON; // turn on the background light 298 backLightState = 1; 299 oldBacklightTime = millis(); 300 newButtonTime = millis(); 301 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 302 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 303//Button 1 304 if(75<p.x && p.x<140){ 305 if(100<p.y && p.y<164){ 306 buttonPressed = 1; 307 } 308//Button 2 309 if(164<p.y && p.y<240){ 310 buttonPressed = 2; 311 } 312//Button 3 313 if(240<p.y && p.y<310){ 314 buttonPressed = 3; 315 } 316 } 317 } 318//Button 4 319 if(10<p.x && p.x<75){ 320 if(100<p.y && p.y<240){ 321 buttonPressed = 4; 322 } 323 } 324}//void tftButtonGroup0 325//--------------------------end tftButtonGroup0 code---------------------------------- 326//--------------------------end tftButtonGroup0 code---------------------------------- 327//--------------------------end tftButtonGroup0 code---------------------------------- 328//--------------------------end tftButtonGroup0 code---------------------------------- 329//--------------------------end tftButtonGroup0 code---------------------------------- 330//**************************************************************************************************** 331//**************************************************************************************************** 332 333//--------------------------begin tftButtonGroup1---------------------------------- 334//--------------------------begin tftButtonGroup1---------------------------------- 335//--------------------------begin tftButtonGroup1---------------------------------- 336//--------------------------begin tftButtonGroup1---------------------------------- 337int tftButtonGroup1(){ // for mouth 338buttonPressed = 0; 339 Point p = ts.getPoint(); 340 if(zMin<p.z && p.z<zMax){ 341 TFT_BL_ON; // turn on the background light 342 backLightState = 1; 343 oldBacklightTime = millis(); 344 newButtonTime = millis(); 345 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 346 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 347//Button 1 348 if(75<p.x && p.x<140){ 349 if(100<p.y && p.y<164){ 350 mouthOnOffNew = 1; // on 351 Serial.print("mouthOnOffNew set to "); 352 Serial.println(mouthOnOffNew); 353 } 354//Button 2 355 if(164<p.y && p.y<240){ 356 mouthOnOffNew = 2; // off 357 Serial.print("mouthOnOffNew set to "); 358 Serial.println(mouthOnOffNew); 359 } 360//Button 3 361// if(240<p.y && p.y<310){ 362// buttonPressed = 3; 363// } 364 } 365 } 366//Button 4 367 if(10<p.x && p.x<75){ 368 if(100<p.y && p.y<240){ 369 buttonPressed = 4; 370 buttonGroup = 0; 371 } 372 } 373}//void tftButtonGroup1 374//--------------------------end tftButtonGroup1 code---------------------------------- 375//--------------------------end tftButtonGroup1 code---------------------------------- 376//--------------------------end tftButtonGroup1 code---------------------------------- 377//--------------------------end tftButtonGroup1 code---------------------------------- 378//--------------------------end tftButtonGroup1 code---------------------------------- 379//**************************************************************************************************** 380//**************************************************************************************************** 381 382//--------------------------begin tftButtonGroup2---------------------------------- 383//--------------------------begin tftButtonGroup2---------------------------------- 384//--------------------------begin tftButtonGroup2---------------------------------- 385//--------------------------begin tftButtonGroup2---------------------------------- 386int tftButtonGroup2(){ // for mouth 387buttonPressed = 0; 388 Point p = ts.getPoint(); 389 if(zMin<p.z && p.z<zMax){ 390 TFT_BL_ON; // turn on the background light 391 backLightState = 1; 392 oldBacklightTime = millis(); 393 newButtonTime = millis(); 394 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 395 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 396//Button 1 397 if(75<p.x && p.x<140){ 398 if(100<p.y && p.y<164){ 399 headOnOffNew = 1; // on 400 Serial.print("headOnOffNew set to "); 401 Serial.println(headOnOffNew); 402 } 403//Button 2 404 if(164<p.y && p.y<240){ 405 headOnOffNew = 2; // off 406 Serial.print("headOnOffNew set to "); 407 Serial.println(headOnOffNew); 408 } 409//Button 3 410// if(240<p.y && p.y<310){ 411// buttonPressed = 3; 412// } 413 } 414 } 415//Button 4 416 if(10<p.x && p.x<75){ 417 if(100<p.y && p.y<240){ 418 buttonPressed = 4; 419 buttonGroup = 0; 420 } 421 } 422}//void tftButtonGroup2 423//--------------------------end tftButtonGroup2 code---------------------------------- 424//--------------------------end tftButtonGroup2 code---------------------------------- 425//--------------------------end tftButtonGroup2 code---------------------------------- 426//--------------------------end tftButtonGroup2 code---------------------------------- 427//--------------------------end tftButtonGroup2 code---------------------------------- 428//**************************************************************************************************** 429//**************************************************************************************************** 430//-------------------------- begin whatScreen function ------------------------- 431//-------------------------- begin whatScreen function ------------------------- 432//-------------------------- begin whatScreen function ------------------------- 433//-------------------------- begin whatScreen function ------------------------- 434 435int whatScreen(){ 436 if(x == 0){ 437 if(buttonPressed == 1){ 438 x = x + 1; 439 Serial.println("x + 1"); 440 } 441 if(buttonPressed == 2){ 442 x = x + 2; 443 Serial.println("x + 2"); 444 } 445 if(buttonPressed == 3){ 446 x = x + 3; 447 Serial.println("x + 3"); 448 } 449 if(buttonPressed == 4){ 450 x = 0; 451 Serial.println("x = 0"); 452 } 453 if(buttonPressed == 5){ 454 x = 0; 455 y = 0; 456 z = 0; 457 Serial.println("xyz all 0"); 458 } 459 } 460 else if(x >> 0){ 461 if(y == 0){ 462 if(buttonPressed == 1){ 463 y = y + 10; 464 Serial.println("y + 10"); 465 } 466 if(buttonPressed == 2){ 467 y = y + 20; 468 Serial.println("y + 20"); 469 } 470 if(buttonPressed == 3){ 471 y = y + 30; 472 Serial.println("y + 30"); 473 } 474 if(buttonPressed == 4){ 475 x = 0; 476 Serial.println("x = 0"); 477 } 478 if(buttonPressed == 5){ 479 x = 0; 480 y = 0; 481 z = 0; 482 Serial.println("xyz all 0"); 483 } 484 } 485 else if (y >> 0){ 486 if(buttonPressed == 1){ 487 z = z + 100; 488 Serial.println("z + 100"); 489 } 490 if(buttonPressed == 2){ 491 z = z + 200; 492 Serial.println("z + 200"); 493 } 494 if(buttonPressed == 3){ 495 z = z + 300; 496 Serial.println("z + 300"); 497 } 498 if(buttonPressed == 4){ 499 if(z == 0){ 500 y = 0; 501 Serial.println("y = 0"); 502 } 503 else if(z >> 0){ 504 z = 0; 505 Serial.println("z = 0"); 506 } 507 } 508 if(buttonPressed == 5){ 509 x = 0; 510 y = 0; 511 z = 0; 512 Serial.println("xyz all 0"); 513 } 514 }//y>0 515 }//x>0 516 currentScreen = z+y+x; 517 if(currentScreen == 122){ 518 buttonGroup=1; 519 } 520 if(currentScreen == 222){ 521 buttonGroup=1; 522 } 523 if(currentScreen == 23){ 524 buttonGroup=2; 525 } 526} 527//-------------------------- end whatScreen function ------------------------- 528//-------------------------- end whatScreen function ------------------------- 529//-------------------------- end whatScreen function ------------------------- 530//-------------------------- end whatScreen function ------------------------- 531//-------------------------- end whatScreen function ------------------------- 532 533//**************************************************************************************************** 534//**************************************************************************************************** 535 536//--------------------------begin mouthUnoTxRx---------------------------------- 537 538void mouthUnoTxRx(){ 539 if(mouthOnOffNew != mouthOnOffOld){ 540 Serial.println("starting txrx"); 541 if(mouthOnOffNew == 1){ 542 Serial.println("Starting tx"); 543 Serial1.flush(); 544 Serial1.write('1'); 545 mouthOnOffOld = 1; 546//begin rx 547 Serial.println("Starting rx"); 548 549 delay(10); // tweak delay to accomodate uno 550 551 // use a serial available after flush funtion while or for loop or interrrupt or somethin 552 incomingMouthByte = Serial1.read(); 553 Serial1.flush(); 554 mouthOnOffAdjusted = incomingMouthByte; 555 Serial.print("mouthOnOffAdjusted should be 1: "); 556 Serial.println(mouthOnOffAdjusted); 557 } 558 if(mouthOnOffNew == 2){ 559 Serial.println("Starting tx"); 560 Serial1.flush(); 561 Serial1.write('2'); 562 mouthOnOffOld = 2; 563//begin rx 564 Serial.println("Starting rx"); 565 566 delay(10); // tweak delay to accomodate uno 567 568 incomingMouthByte = Serial1.read(); 569 Serial1.flush(); 570 mouthOnOffAdjusted = incomingMouthByte; 571 Serial.print("mouthOnOffAdjusted should be 2: "); 572 Serial.println(mouthOnOffAdjusted); 573 } 574 else if(mouthOnOffAdjusted != 1 && mouthOnOffAdjusted != 2){ 575 Serial.println("error reply wasn't like expected"); 576 Serial.print("instead, the adjusted reply was"); 577 578 delay(10); // tweak delay to accomodate uno 579 580 incomingMouthByte = Serial1.read(); 581 Serial1.flush(); 582 mouthOnOffAdjusted = incomingMouthByte; 583 Serial.print("mouthOnOffAdjusted: "); 584 Serial.println(mouthOnOffAdjusted); 585 } 586 } 587 else if(mouthOnOffOld = mouthOnOffNew){ 588 } 589 Serial.flush(); 590 Serial1.flush(); 591} 592 593//--------------------------end mouthUnoTxRx -------------------------------------- 594//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 595//--------------------------begin headUnoTxRx---------------------------------- 596 597void headUnoTxRx(){ 598 if(headOnOffNew != headOnOffOld){ 599 Serial.println("starting txrx"); 600 if(headOnOffNew == 1){ 601 Serial.println("Starting tx"); 602 Serial2.flush(); 603 Serial2.write('1'); 604 headOnOffOld = 1; 605//begin rx 606 Serial.println("Starting rx"); 607 608 delay(10); // tweak delay to accomodate uno 609 610 // use a serial available after flush funtion while or for loop or interrrupt or somethin instead of delay 611 incomingHeadByte = Serial2.read(); 612 Serial2.flush(); 613 headOnOffAdjusted = incomingHeadByte; 614 Serial.print("headOnOffAdjusted should be 1: "); 615 Serial.println(headOnOffAdjusted); 616 } 617 if(headOnOffNew == 2){ 618 Serial.println("Starting tx"); 619 Serial2.flush(); 620 Serial2.write('2'); 621 headOnOffOld = 2; 622//begin rx 623 Serial.println("Starting rx"); 624 625 delay(10); // tweak delay to accomodate uno 626 627 incomingHeadByte = Serial2.read(); 628 Serial2.flush(); 629 headOnOffAdjusted = incomingHeadByte; 630 Serial.print("headOnOffAdjusted should be 2: "); 631 Serial.println(headOnOffAdjusted); 632 } 633 else if(headOnOffAdjusted != 1 && headOnOffAdjusted != 2){ 634 Serial.println("error reply wasn't like expected"); 635 Serial.print("instead, the adjusted reply was"); 636 637 delay(10); // tweak delay to accomodate uno 638 639 incomingHeadByte = Serial2.read(); 640 Serial2.flush(); 641 headOnOffAdjusted = incomingHeadByte; 642 Serial.print("headOnOffAdjusted: "); 643 Serial.println(headOnOffAdjusted); 644 } 645 } 646 else if(headOnOffOld = headOnOffNew){ 647 } 648 Serial.flush(); 649 Serial2.flush(); 650} 651 652//--------------------------end headUnoTxRx -------------------------------------- 653//**************************************************************************************************** 654//**************************************************************************************************** 655 656//--------------------------begin tftDisplay code---------------------------------- 657void tftDisplay(){ 658 Point p = ts.getPoint(); 659 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 660 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 661 662 Tft.fillRectangle(70, 100, 60, 30, BLACK); 663 Tft.drawNumber((buttonGroup), 70, 100, 3, GREEN); 664 Tft.fillRectangle(140, 100, 60, 30, BLACK); 665 Tft.drawNumber((mouthOnOffNew), 140, 100, 3, GREEN); 666 Tft.fillRectangle(160, 100, 60, 30, BLACK); 667 Tft.drawNumber((headOnOffNew), 160, 100, 3, GREEN); 668 Tft.fillRectangle(0, 225, 60, 30, BLACK); 669 Tft.drawNumber((p.x), 0, 225, 3, GREEN); 670 Tft.fillRectangle(180, 225, 60, 30, BLACK); 671 Tft.drawNumber((p.y), 180, 225, 3, GREEN); 672 Tft.fillRectangle(100, 225, 60, 30, BLACK); 673 Tft.drawNumber((buttonPressed), 100, 225, 3, GREEN); 674 Tft.fillRectangle(120, 290, 60, 30, BLACK); 675 Tft.drawNumber((currentScreen), 120, 290, 3, GREEN); 676 677 678}// void tftDisplay 679//--------------------------end tftDisplay code------------------------------------ 680 681//**************************************************************************************************** 682//**************************************************************************************************** 683 684//-------------------------- begin mouth on off function -------------------------- 685//-------------------------- end mouth on off function -------------------------- 686 687//**************************************************************************************************** 688//**************************************************************************************************** 689 690//-------------------------- begin head on off function -------------------------- 691//-------------------------- end head on off function ------------------------- 692 693//**************************************************************************************************** 694//**************************************************************************************************** 695 696//-------------------------- begin serial display function -------------------------- 697void showStuff(){ 698 Serial.println("------/ last update /-------"); 699// Serial.println("------begin display-------"); 700 Serial.print("buttonPressed "); 701 Serial.println(buttonPressed); 702 Serial.print("x "); 703 Serial.println(x); 704 Serial.print("y "); 705 Serial.println(y); 706 Serial.print("z "); 707 Serial.println(z); 708 Serial.print("currentScreen "); 709 Serial.println(currentScreen); 710// Serial.println("-------end display--------"); 711 Serial.println(""); 712 Serial.println(""); 713 Serial.println(""); 714 } 715//-------------------------- end serial display function ------------------------- 716 717 718//**************************************************************************************************** 719//**************************************************************************************************** 720 721//--------------------------- Primary screen maps -------------------------------- 722/* 723******** 724updates needed 725******** 7261 ditch the contrast 7272 ditch the brightness 7283 setup screen timeout 729 730 731 732 733screen 0000 A)Home 734 screen 0001 a)settings 735 screen 0011 -brightness 736 screen 0011 -contrast 737 screen 0011 -screen lock time out 738 screen 0001 b)sensor monitors 739 screen 0021 -pir 740 screen 0121 *report pir detection 741 screen 0021 -sound 742 screen 0221 *sense alexa sound 743 screen 0221 *sense graves sound 744 screen 0221 *report mouth servo position 745 screen 0221 *adjust sensitivity? 746 screen 0021 -head potentiometer 747 screen 0021 -bluetooth 748 screen 0001 c)bluetooth 749 screen 0031 -on 750 screen 0031 -off 751 screen 0031 -monitor 752screen 0000 B)Mouth Control 753 screen 0002 a)test button 754 screen 0012 -open 755 screen 0012 -close 756 screen 0012 -push button chicken switch 757 screen 0002 b)sound sensors on/off 758 screen 0022 -alexa sense 759 screen 0122 *on 760 screen 0122 *off 761 screen 0122 *monitor sensor 762 screen 0022 -graves sense 763 screen 0222 *on 764 screen 0222 *off 765 screen 0222 *monitor sensors 766 screen 0002 c)sound sensor status 767 screen 0032 -alexa 768 screen 0032 -graves 769screen 0000 C)Head Control 770 screen 0003 a)pir on/off 771 screen 0013 -on 772 screen 0013 -off 773 screen 0013 -sensor 774 screen 0003 b)manual point 775 screen 0023 -slider 776*/ 777//**************************************************************************************************** 778//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 779//**************************************************************************************************** 780//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 781//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 782//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 783//**************************************************************************************************** 784//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 785//**************************************************************************************************** 786 787//-------------------------- begin callScreen function ------------------------- 788//-------------------------- begin callScreen function ------------------------- 789//-------------------------- begin callScreen function ------------------------- 790//-------------------------- begin callScreen function ------------------------- 791//-------------------------- begin callScreen function ------------------------- 792//-------------------------- begin callScreen function ------------------------- 793//-------------------------- begin callScreen function ------------------------- 794//-------------------------- begin callScreen function ------------------------- 795//-------------------------- begin callScreen function ------------------------- 796//-------------------------- begin callScreen function ------------------------- 797//-------------------------- begin callScreen function ------------------------- 798 799int callScreen(){ 800 Tft.fillRectangle(0, 0, 240, 320, BLACK); 801 802//<><><><><><><><><><><><><><><><><><><><><><><><> 803//<><><><><><><><> begin screen 0000 master <><><><><><><><> 804//<><><><><><><><><><><><><><><><><><><><><><><><> 805if(currentScreen == 0){ 806 // " " 807 Tft.drawString("GRAVES",0,5,4, GREEN); 808 Tft.drawString("INTERFACE",10,50,4,GREEN); 809 Tft.drawString("Home", 80,130, 3, GREEN); 810 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 811 Tft.drawString("Head Control", 10, 260, 3, GREEN); 812} 813//<><><><><><><><><><><><><><><><><><><><><><><><> 814//<><><><><><><><> end screen 0000 master <><><><><><><><><> 815//<><><><><><><><><><><><><><><><><><><><><><><><> 816 817//<><><><><><><><><><><><><><><><><><><><><><><><> 818//<><><><><><><><> begin screen 0001 <><><><><><><><> 819//<><><><><><><><><><><><><><><><><><><><><><><><> 820 if(currentScreen == 1){ 821 // " " 822 Tft.drawString("MEGA 2560",00,5,4,BLUE); 823 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 824 Tft.drawString("Settings", 10,130, 3, BLUE); 825 Tft.drawString("Sensors", 20, 195, 3, BLUE); 826 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 827 Tft.drawString("<", 0, 160, 3, GREEN); // back button 828} 829//<><><><><><><><><><><><><><><><><><><><><><><><> 830//<><><><><><><><> end screen 0001 <><><><><><><><><> 831//<><><><><><><><><><><><><><><><><><><><><><><><> 832 833//<><><><><><><><><><><><><><><><><><><><><><><><> 834//<><><><><><><><> begin screen 0011 <><><><><><><><> 835//<><><><><><><><><><><><><><><><><><><><><><><><> 836 if(currentScreen == 11){ 837 // " " 838 Tft.drawString("MEGA 2560",00,5,4,BLUE); 839 Tft.drawString("SETTINGS",10,50,4,YELLOW); 840 Tft.drawString("Brightness", 80,130, 3, BLUE); 841 Tft.drawString("Contrast", 05, 195, 3, GREEN); 842 Tft.drawString("Timeout", 10, 260, 3, GREEN); 843 Tft.drawString("<", 0, 160, 3, GREEN); // back button 844} 845 846//<><><><><><><><><><><><><><><><><><><><><><><><> 847//<><><><><><><><> end screen 0011 <><><><><><><><><> 848//<><><><><><><><><><><><><><><><><><><><><><><><> 849 850//<><><><><><><><><><><><><><><><><><><><><><><><> 851//<><><><><><><><> begin screen 0021 <><><><><><><><> 852//<><><><><><><><><><><><><><><><><><><><><><><><> 853 if(currentScreen == 21){ 854 // " " 855 Tft.drawString("MEGA 2560",00,5,4,BLUE); 856 Tft.drawString("SENSORS",10,50,4,YELLOW); 857 Tft.drawString("PIR Array", 80,130, 3, BLUE); 858 Tft.drawString("Sound", 05, 195, 3, GREEN); 859 Tft.drawString("Head Position", 10, 260, 3, GREEN); 860 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 861 Tft.drawString("<", 0, 160, 3, GREEN); // back button 862} 863//<><><><><><><><><><><><><><><><><><><><><><><><> 864//<><><><><><><><> end screen 0021 <><><><><><><><><> 865//<><><><><><><><><><><><><><><><><><><><><><><><> 866 867//<><><><><><><><><><><><><><><><><><><><><><><><> 868//<><><><><><><><> begin screen 0121 <><><><><><><><> 869//<><><><><><><><><><><><><><><><><><><><><><><><> 870 if(currentScreen == 121){ 871 // " " 872 Tft.drawString("PIR",0,5,4,BLUE); 873 Tft.drawString("ARRAY",10,50,4,YELLOW); 874 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 875 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 876 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 877 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 878 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 879 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 880 Tft.drawString("<", 0, 160, 3, GREEN); // back button 881} 882//<><><><><><><><><><><><><><><><><><><><><><><><> 883//<><><><><><><><> end screen 0121 <><><><><><><><><> 884//<><><><><><><><><><><><><><><><><><><><><><><><> 885 886//<><><><><><><><><><><><><><><><><><><><><><><><> 887//<><><><><><><><> begin screen 0221 <><><><><><><><> 888//<><><><><><><><><><><><><><><><><><><><><><><><> 889 if(currentScreen == 221){ 890 // " " 891 Tft.drawString("SOUND",0,5,4,BLUE); 892 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 893 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 894 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 895 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 896 Tft.drawString("<", 0, 160, 3, GREEN); // back button 897} 898//<><><><><><><><><><><><><><><><><><><><><><><><> 899//<><><><><><><><> end screen 0221 <><><><><><><><><> 900//<><><><><><><><><><><><><><><><><><><><><><><><> 901 902//<><><><><><><><><><><><><><><><><><><><><><><><> 903//<><><><><><><><> begin screen 0031 <><><><><><><><> 904//<><><><><><><><><><><><><><><><><><><><><><><><> 905 if(currentScreen == 31){ 906 // " " 907 Tft.drawString("Bluetooth",0,5,4,BLUE); 908 Tft.drawString("Control",10,50,4,YELLOW); 909 Tft.drawString("On", 80,130, 3, BLUE); 910 Tft.drawString("Off", 05, 195, 3, GREEN); 911 Tft.drawString("Monitor", 10, 260, 3, GREEN); 912 Tft.drawString("<", 0, 160, 3, GREEN); // back button 913} 914//<><><><><><><><><><><><><><><><><><><><><><><><> 915//<><><><><><><><> end screen 0031 <><><><><><><><><> 916//<><><><><><><><><><><><><><><><><><><><><><><><> 917 918//<><><><><><><><><><><><><><><><><><><><><><><><> 919//<><><><><><><><> begin screen 0002 <><><><><><><><> 920//<><><><><><><><><><><><><><><><><><><><><><><><> 921 if(currentScreen == 2){ 922 // " " 923 Tft.drawString("Mouth",0,5,4,BLUE); 924 Tft.drawString("Control",10,50,4,YELLOW); 925 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 926 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 927 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 928 Tft.drawString("<", 0, 160, 3, GREEN); // back button 929 } 930//<><><><><><><><><><><><><><><><><><><><><><><><> 931//<><><><><><><><> end screen 0002 <><><><><><><><><> 932//<><><><><><><><><><><><><><><><><><><><><><><><> 933 934 935//<><><><><><><><><><><><><><><><><><><><><><><><> 936//<><><><><><><><> begin screen 0012 <><><><><><><><> 937//<><><><><><><><><><><><><><><><><><><><><><><><> 938 if(currentScreen == 12){ 939 // " " 940 Tft.drawString("Jaw Test",0,5,4,BLUE); 941 Tft.drawString("Operations",10,50,4,YELLOW); 942 Tft.drawString("Open", 80,130, 3, BLUE); 943 Tft.drawString("Close", 05, 195, 3, GREEN); 944 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 945 Tft.drawString("<", 0, 160, 3, GREEN); // back button 946} 947//<><><><><><><><><><><><><><><><><><><><><><><><> 948//<><><><><><><><> end screen 0012 <><><><><><><><><> 949//<><><><><><><><><><><><><><><><><><><><><><><><> 950 951 952//<><><><><><><><><><><><><><><><><><><><><><><><> 953//<><><><><><><><> begin screen 0022 <><><><><><><><> 954//<><><><><><><><><><><><><><><><><><><><><><><><> 955 if(currentScreen == 22){ 956 // " " 957 Tft.drawString("Sound",0,5,4,BLUE); 958 Tft.drawString("Sensors",10,50,4,YELLOW); 959 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 960 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 961 Tft.drawString("Monitor", 10, 260, 3, GREEN); 962 Tft.drawString("<", 0, 160, 3, GREEN); // back button 963} 964//<><><><><><><><><><><><><><><><><><><><><><><><> 965//<><><><><><><><> end screen 0022 <><><><><><><><><> 966//<><><><><><><><><><><><><><><><><><><><><><><><> 967 968 969 970//<><><><><><><><><><><><><><><><><><><><><><><><> 971//<><><><><><><><> begin screen 0122 <><><><><><><><> 972//<><><><><><><><><><><><><><><><><><><><><><><><> 973 if(currentScreen == 122){ 974 // " " 975 Tft.drawString("Alexa Sense",0,5,4,BLUE); 976 Tft.drawString("Operations",10,50,4,YELLOW); 977 Tft.drawString("On", 120, 130, 3, GREEN); 978 Tft.drawString("Off", 115, 195, 3, RED); 979 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 980 Tft.drawString("<", 0, 160, 3, GREEN); // back button 981} 982//<><><><><><><><><><><><><><><><><><><><><><><><> 983//<><><><><><><><> end screen 0122 <><><><><><><><><> 984//<><><><><><><><><><><><><><><><><><><><><><><><> 985 986//<><><><><><><><><><><><><><><><><><><><><><><><> 987//<><><><><><><><> begin screen 0222 <><><><><><><><> 988//<><><><><><><><><><><><><><><><><><><><><><><><> 989 if(currentScreen == 222){ 990 // " " 991 Tft.drawString("Graves Sense",0,5,4,BLUE); 992 Tft.drawString("Operations",10,50,4,YELLOW); 993 Tft.drawString("On", 120, 130, 3, GREEN); 994 Tft.drawString("Off", 115, 195, 3, RED); 995 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 996 Tft.drawString("<", 0, 160, 3, GREEN); // back button 997} 998//<><><><><><><><><><><><><><><><><><><><><><><><> 999//<><><><><><><><> end screen 0222 <><><><><><><><><> 1000//<><><><><><><><><><><><><><><><><><><><><><><><> 1001 1002//<><><><><><><><><><><><><><><><><><><><><><><><> 1003//<><><><><><><><> begin screen 0032 <><><><><><><><> 1004//<><><><><><><><><><><><><><><><><><><><><><><><> 1005 if(currentScreen == 32){ 1006 // " " 1007 Tft.drawString("Sound Sense",0,5,4,BLUE); 1008 Tft.drawString("Monitors",10,50,4,YELLOW); 1009 Tft.drawString("Alexa", 80,130, 3, BLUE); 1010 Tft.drawString("Graves", 05, 195, 3, GREEN); 1011 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1012} 1013//<><><><><><><><><><><><><><><><><><><><><><><><> 1014//<><><><><><><><> end screen 0032 <><><><><><><><><> 1015//<><><><><><><><><><><><><><><><><><><><><><><><> 1016 1017//<><><><><><><><><><><><><><><><><><><><><><><><> 1018//<><><><><><><><> begin screen 0003 <><><><><><><><> 1019//<><><><><><><><><><><><><><><><><><><><><><><><> 1020 if(currentScreen == 3){ 1021 // " " 1022 Tft.drawString("Head Control",0,5,4,BLUE); 1023 Tft.drawString("Operations",10,50,4,YELLOW); 1024 Tft.drawString("PIR Array", 80,130, 3, BLUE); 1025 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 1026 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 1027 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1028} 1029//<><><><><><><><><><><><><><><><><><><><><><><><> 1030//<><><><><><><><> end screen 0003 <><><><><><><><><> 1031//<><><><><><><><><><><><><><><><><><><><><><><><> 1032 1033//<><><><><><><><><><><><><><><><><><><><><><><><> 1034//<><><><><><><><> begin screen 0013 <><><><><><><><> 1035//<><><><><><><><><><><><><><><><><><><><><><><><> 1036 if(currentScreen == 13){ 1037 // " " 1038 Tft.drawString("PIR Control",0,5,4,BLUE); 1039 Tft.drawString("Operations",10,50,4,YELLOW); 1040 Tft.drawString("On", 80,130, 3, BLUE); 1041 Tft.drawString("Off", 05, 195, 3, GREEN); 1042 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 1043 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1044} 1045//<><><><><><><><><><><><><><><><><><><><><><><><> 1046//<><><><><><><><> end screen 0013 <><><><><><><><><> 1047//<><><><><><><><><><><><><><><><><><><><><><><><> 1048 1049//<><><><><><><><><><><><><><><><><><><><><><><><> 1050//<><><><><><><><> begin screen 0023 <><><><><><><><> 1051//<><><><><><><><><><><><><><><><><><><><><><><><> 1052 if(currentScreen == 23){ 1053 // " " 1054 Tft.drawString("Graves Head",0,5,3,BLUE); 1055 Tft.drawString("Operations",10,50,3,YELLOW); 1056 Tft.drawString("On", 120, 130, 3, GREEN); 1057 Tft.drawString("Off", 115, 195, 3, RED); 1058// Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1059 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1060} 1061//<><><><><><><><><><><><><><><><><><><><><><><><> 1062//<><><><><><><><> end screen 0023 <><><><><><><><><> 1063//<><><><><><><><><><><><><><><><><><><><><><><><> 1064 1065 1066//<><><><><><><><><><><><><><><><><><><><><><><><> 1067//<><><><><><><><> begin screen 0422 <><><><><><><><> 1068//<><><><><><><><><><><><><><><><><><><><><><><><> 1069 if(currentScreen == 422){ 1070 // " " 1071 Tft.drawString("Command Sent",0,5,3,BLUE); 1072 Tft.drawString("Press Back to",0,55,3,YELLOW); 1073 Tft.drawString("Contiue", 50,105, 3, BLUE); 1074 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1075} 1076//<><><><><><><><><><><><><><><><><><><><><><><><> 1077//<><><><><><><><> end screen 0422 <><><><><><><><><> 1078//<><><><><><><><><><><><><><><><><><><><><><><><> 1079 1080 1081////<><><><><><><><><><><><><><><><><><><><><><><><> 1082////<><><><><><><><> begin screen lost <><><><><><><><> 1083////<><><><><><><><><><><><><><><><><><><><><><><><> 1084// else if(currentScreen){ 1085// // " " 1086// Tft.drawString("Screen not",0,5,3,BLUE); 1087// Tft.drawString("found. Please",40,50,3,YELLOW); 1088// Tft.drawString("use the back", 80,130, 3, BLUE); 1089// Tft.drawString("button to", 05, 195, 3, GREEN); 1090// Tft.drawString("return to fun", 10, 260, 3, GREEN); 1091// Tft.drawString("<", 0, 160, 3, GREEN); // back button 1092//} 1093////<><><><><><><><><><><><><><><><><><><><><><><><> 1094////<><><><><><><><> end screen lost <><><><><><><><><> 1095////<><><><><><><><><><><><><><><><><><><><><><><><> 1096 1097}// callScreen 1098//-------------------------- end callScreen function ------------------------- 1099//-------------------------- end callScreen function ------------------------- 1100//-------------------------- end callScreen function ------------------------- 1101//-------------------------- end callScreen function ------------------------- 1102//-------------------------- end callScreen function ------------------------- 1103//-------------------------- end callScreen function ------------------------- 1104//-------------------------- end callScreen function ------------------------- 1105//-------------------------- end callScreen function ------------------------- 1106//-------------------------- end callScreen function ------------------------- 1107//-------------------------- end callScreen function ------------------------- 1108//-------------------------- end callScreen function ------------------------- 1109//-------------------------- end callScreen function ------------------------- 1110//-------------------------- end callScreen function ------------------------- 1111 1112 1113//**************************************************************************************************** 1114//**************************************************************************************************** 1115 1116 1117 1118 1119 1120 1121 1122//**************************************************************************************************** 1123//**************************************************************************************************** 1124 1125// fin
button groups refined
c_cpp
this updated interface deals with changing button areas based on screen number
1/* 2last edit sunday oct 14 2018 midnight 3 4 5gravesmegamaster 6 7graves project 8arduino MEGA 2650 9Master 10coded from scratch by wylie jones 11wyliejones@gmail.com 12 13Graves multi arduino build 10/2018 14Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 15two arduino uno's 16slave1 arduino uno to sense sound from graves and echo dot to control mouth 17slave2 arduino uno to control passive sensor array and head servo 18 19sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 20 21 analogue pin speaker + 22 \ / (red from speaker) 23 \ / 24 \ / 25 *--------[=]-----------*---------[=]----------* 26 | resistor \ resistor | 27 | \ | 28 |(red with white) \ |to arduino ground (black with white) 29to arduino 5v+ speaker - 30 (black from speaker) 31 32*/ 33//end notes 34//end notes 35//end notes 36//end notes 37//end notes 38//end notes 39 40 41//********************************************************* 42//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 43//********************************************************* 44 45 46//begin declarations 47//begin declarations 48//begin declarations 49//begin declarations 50//begin declarations 51//begin declarations 52//begin declarations 53 54//#include <TFT.h> 55//#include <Servo.h> 56//#include <stdint.h> 57//#include <SD.h> 58#include <TFTv2.h> 59#include <SPI.h> 60#include <SeeedTouchScreen.h> 61 62//const int PIN_SD_CS = 4; // pin of sd card 63 64TouchScreen ts = TouchScreen(XP, YP, XM, YM); 65int zMax; // maximum pressure to detect 66int zMin; // minimum pressure to detect 67 68int buttonPressed; // stores which button was pressed 69unsigned long newButtonTime; // debounce 70unsigned long oldButtonTime; // debounce 71unsigned long buttonTimeDifference; // debounce 72unsigned long debounceTime; // debounce 73int buttonGroup; // sets kinds of buttons on screen 74 75int currentScreen; // identifies current screen by adding x y and z 76int x; // for ones 77int y; // for tens 78int z; // for hundreds 79 80unsigned long backlightTimer; // for backlight timeout 81int backLightState; // status of backlight 1 for on and 0 for off 82unsigned long backlightTimeDifference; 83unsigned long newBacklightTime; 84unsigned long oldBacklightTime; 85 86int incomingMouthByte; 87int outgoingMouthByte; 88int mouthOnOff; 89 90int incomingHeadByte; 91int outgoingHeadByte; 92int headOnOff; 93 94//end declarations 95//end declarations 96//end declarations 97//end declarations 98//end declarations 99//end declarations 100//end declarations 101//end declarations 102//end declarations 103 104//********************************************************* 105//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 106//********************************************************* 107 108// begin void setup 109// begin void setup 110// begin void setup 111// begin void setup 112// begin void setup 113// begin void setup 114// begin void setup 115// begin void setup 116// begin void setup 117// begin void setup 118// begin void setup 119void setup() { 120Serial.begin(9600); 121 oldButtonTime = millis(); 122 newButtonTime = millis(); 123 Tft.TFTinit(); // init TFT library 124 TFT_BL_ON; // turn on the background light 125 backLightState = 1; 126 x = 0; 127 y = 0; 128 z = 0; 129 buttonPressed = 4; 130 buttonGroup = 0; 131 incomingHeadByte = 0; 132 incomingMouthByte = 0; 133 134 //////////////////////////////// 135 //// manually set variables //// 136 //////////////////////////////// 137 138 debounceTime = 1000; // button debounce in milliseconds 139 zMax = 460; // maximum pressure to detect 140 zMin = 100; // minimum pressure to detect 141 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 142 143 144 currentScreen = 0; 145 callScreen(); 146 147} //void setup() 148// end void setup 149// end void setup 150// end void setup 151// end void setup 152// end void setup 153// end void setup 154// end void setup 155// end void setup 156 157//********************************************************* 158//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 159//********************************************************* 160 161// begin void loop 162// begin void loop 163// begin void loop 164// begin void loop 165// begin void loop 166// begin void loop 167// begin void loop 168// begin void loop 169// begin void loop 170// begin void loop 171// begin void loop 172// begin void loop 173// begin void loop 174// begin void loop 175 176void loop() { 177 tftBacklightTimeout(); // check time and turn off backlight 178 179if(buttonGroup == 0){ 180 tftButtonGroup0(); // gather information from touch screen touches 181 buttonTimeDifference = newButtonTime - oldButtonTime; 182 if(debounceTime < buttonTimeDifference){ 183 whatScreen(); 184 callScreen(); 185 oldButtonTime = newButtonTime; 186 showStuff(); // serial prints 187 tftDisplay(); // display x y coordinates on tft display 188 } 189} 190if(buttonGroup == 1){ 191 tftButtonGroup1(); // gather information from touch screen touches 192 buttonTimeDifference = newButtonTime - oldButtonTime; 193 if(debounceTime < buttonTimeDifference){ 194 whatScreen(); 195 callScreen(); 196 oldButtonTime = newButtonTime; 197 showStuff(); // serial prints 198 tftDisplay(); // display x y coordinates on tft display 199 } 200} 201if(buttonGroup == 2){ 202 tftButtonGroup2(); // gather information from touch screen touches 203 buttonTimeDifference = newButtonTime - oldButtonTime; 204 if(debounceTime < buttonTimeDifference){ 205 whatScreen(); 206 callScreen(); 207 oldButtonTime = newButtonTime; 208 showStuff(); // serial prints 209 tftDisplay(); // display x y coordinates on tft display 210 } 211} 212 213// serialDoStuff(); 214} //void loop() 215 216// end of void loop 217// end of void loop 218// end of void loop 219// end of void loop 220// end of void loop 221// end of void loop 222// end of void loop 223// end of void loop 224// end of void loop 225// end of void loop 226// end of void loop 227// end of void loop 228// end of void loop 229// end of void loop 230// end of void loop 231 232//**************************************************************************************************** 233//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 234//**************************************************************************************************** 235///////////////////////////////////////////////////////////////////////////////////////////////////////// 236///////////////////////////////////////// functions /////////////////////////////////////////////////// 237///////////////////////////////////////////////////////////////////////////////////////////////////////// 238//**************************************************************************************************** 239//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 240//**************************************************************************************************** 241 242//--------------------------begin tftBacklightTimeout---------------------------------- 243void tftBacklightTimeout(){ 244 newBacklightTime = millis(); 245 if(backLightState = 0){ 246 backlightTimeDifference = newBacklightTime - oldBacklightTime; 247 if(backlightTimer > backlightTimeDifference){ 248 backlightTimeDifference = newBacklightTime - oldBacklightTime; 249 TFT_BL_ON; // turn on the background light 250 backLightState = 1; 251 oldBacklightTime = millis(); 252 } 253 } 254 if(backLightState = 1){ 255 backlightTimeDifference = newBacklightTime - oldBacklightTime; 256 if(backlightTimer < backlightTimeDifference){ 257 backlightTimeDifference = newBacklightTime - oldBacklightTime; 258 TFT_BL_OFF; // turn off the background light 259 backLightState = 0; 260 oldBacklightTime = millis(); 261 } 262 } 263} 264//--------------------------end tftBacklightTimeout---------------------------------- 265 266//**************************************************************************************************** 267//**************************************************************************************************** 268 269//--------------------------begin tftButtonGroup0---------------------------------- 270//--------------------------begin tftButtonGroup0---------------------------------- 271//--------------------------begin tftButtonGroup0---------------------------------- 272//--------------------------begin tftButtonGroup0---------------------------------- 273int tftButtonGroup0(){ 274 Point p = ts.getPoint(); 275 if(zMin<p.z && p.z<zMax){ 276 TFT_BL_ON; // turn on the background light 277 backLightState = 1; 278 oldBacklightTime = millis(); 279 newButtonTime = millis(); 280 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 281 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 282//Button 1 283 if(75<p.x && p.x<140){ 284 if(100<p.y && p.y<164){ 285 buttonPressed = 1; 286 } 287//Button 2 288 if(164<p.y && p.y<240){ 289 buttonPressed = 2; 290 } 291//Button 3 292 if(240<p.y && p.y<310){ 293 buttonPressed = 3; 294 } 295 } 296 } 297//Button 4 298 if(10<p.x && p.x<75){ 299 if(100<p.y && p.y<240){ 300 buttonPressed = 4; 301 } 302 } 303}//void tftButtonGroup0 304//--------------------------end tftButtonGroup0 code---------------------------------- 305//--------------------------end tftButtonGroup0 code---------------------------------- 306//--------------------------end tftButtonGroup0 code---------------------------------- 307//--------------------------end tftButtonGroup0 code---------------------------------- 308//--------------------------end tftButtonGroup0 code---------------------------------- 309//**************************************************************************************************** 310//**************************************************************************************************** 311 312//--------------------------begin tftButtonGroup1---------------------------------- 313//--------------------------begin tftButtonGroup1---------------------------------- 314//--------------------------begin tftButtonGroup1---------------------------------- 315//--------------------------begin tftButtonGroup1---------------------------------- 316int tftButtonGroup1(){ // for mouth 317buttonPressed = 0; 318 Point p = ts.getPoint(); 319 if(zMin<p.z && p.z<zMax){ 320 TFT_BL_ON; // turn on the background light 321 backLightState = 1; 322 oldBacklightTime = millis(); 323 newButtonTime = millis(); 324 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 325 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 326//Button 1 327 if(75<p.x && p.x<140){ 328 if(100<p.y && p.y<164){ 329 mouthOnOff = 1; // on 330 } 331//Button 2 332 if(164<p.y && p.y<240){ 333 mouthOnOff = 0; // off 334 } 335//Button 3 336// if(240<p.y && p.y<310){ 337// buttonPressed = 3; 338// } 339 } 340 } 341//Button 4 342 if(10<p.x && p.x<75){ 343 if(100<p.y && p.y<240){ 344 buttonPressed = 4; 345 buttonGroup = 0; 346 } 347 } 348}//void tftButtonGroup1 349//--------------------------end tftButtonGroup1 code---------------------------------- 350//--------------------------end tftButtonGroup1 code---------------------------------- 351//--------------------------end tftButtonGroup1 code---------------------------------- 352//--------------------------end tftButtonGroup1 code---------------------------------- 353//--------------------------end tftButtonGroup1 code---------------------------------- 354//**************************************************************************************************** 355//**************************************************************************************************** 356 357//--------------------------begin tftButtonGroup2---------------------------------- 358//--------------------------begin tftButtonGroup2---------------------------------- 359//--------------------------begin tftButtonGroup2---------------------------------- 360//--------------------------begin tftButtonGroup2---------------------------------- 361int tftButtonGroup2(){ // for head 362buttonPressed = 0; 363 Point p = ts.getPoint(); 364 if(zMin<p.z && p.z<zMax){ 365 TFT_BL_ON; // turn on the background light 366 backLightState = 1; 367 oldBacklightTime = millis(); 368 newButtonTime = millis(); 369 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 370 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 371//Button 1 372 if(75<p.x && p.x<140){ 373 if(100<p.y && p.y<164){ 374 headOnOff = 1; // on 375 } 376//Button 2 377 if(164<p.y && p.y<240){ 378 headOnOff = 0; // off 379 } 380//Button 3 381// if(240<p.y && p.y<310){ 382// buttonPressed = 3; 383// } 384 } 385 } 386//Button 4 387 if(10<p.x && p.x<75){ 388 if(100<p.y && p.y<240){ 389 buttonPressed = 4; 390 buttonGroup = 0; 391 } 392 } 393}//void tftButtonGroup2 394//--------------------------end tftButtonGroup2 code---------------------------------- 395//--------------------------end tftButtonGroup2 code---------------------------------- 396//--------------------------end tftButtonGroup2 code---------------------------------- 397//--------------------------end tftButtonGroup2 code---------------------------------- 398//--------------------------end tftButtonGroup2 code---------------------------------- 399//**************************************************************************************************** 400//**************************************************************************************************** 401//-------------------------- begin whatScreen function ------------------------- 402//-------------------------- begin whatScreen function ------------------------- 403//-------------------------- begin whatScreen function ------------------------- 404//-------------------------- begin whatScreen function ------------------------- 405 406int whatScreen(){ 407 if(x == 0){ 408 if(buttonPressed == 1){ 409 x = x + 1; 410 Serial.println("x + 1"); 411 } 412 if(buttonPressed == 2){ 413 x = x + 2; 414 Serial.println("x + 2"); 415 } 416 if(buttonPressed == 3){ 417 x = x + 3; 418 Serial.println("x + 3"); 419 } 420 if(buttonPressed == 4){ 421 x = 0; 422 Serial.println("x = 0"); 423 } 424 if(buttonPressed == 5){ 425 x = 0; 426 y = 0; 427 z = 0; 428 Serial.println("xyz all 0"); 429 } 430 } 431 else if(x >> 0){ 432 if(y == 0){ 433 if(buttonPressed == 1){ 434 y = y + 10; 435 Serial.println("y + 10"); 436 } 437 if(buttonPressed == 2){ 438 y = y + 20; 439 Serial.println("y + 20"); 440 } 441 if(buttonPressed == 3){ 442 y = y + 30; 443 Serial.println("y + 30"); 444 } 445 if(buttonPressed == 4){ 446 x = 0; 447 Serial.println("x = 0"); 448 } 449 if(buttonPressed == 5){ 450 x = 0; 451 y = 0; 452 z = 0; 453 Serial.println("xyz all 0"); 454 } 455 } 456 else if (y >> 0){ 457 if(buttonPressed == 1){ 458 z = z + 100; 459 Serial.println("z + 100"); 460 } 461 if(buttonPressed == 2){ 462 z = z + 200; 463 Serial.println("z + 200"); 464 } 465 if(buttonPressed == 3){ 466 z = z + 300; 467 Serial.println("z + 300"); 468 } 469 if(buttonPressed == 4){ 470 if(z == 0){ 471 y = 0; 472 Serial.println("y = 0"); 473 } 474 else if(z >> 0){ 475 z = 0; 476 Serial.println("z = 0"); 477 } 478 } 479 if(buttonPressed == 5){ 480 x = 0; 481 y = 0; 482 z = 0; 483 Serial.println("xyz all 0"); 484 } 485 }//y>0 486 }//x>0 487 currentScreen = z+y+x; 488 if(currentScreen == 122){ 489 buttonGroup=1; 490 } 491 if(currentScreen == 222){ 492 buttonGroup=1; 493 } 494 if(currentScreen == 23){ 495 buttonGroup=2; 496 } 497} 498//-------------------------- end whatScreen function ------------------------- 499//-------------------------- end whatScreen function ------------------------- 500//-------------------------- end whatScreen function ------------------------- 501//-------------------------- end whatScreen function ------------------------- 502//-------------------------- end whatScreen function ------------------------- 503 504//**************************************************************************************************** 505//**************************************************************************************************** 506 507//--------------------------begin mouthUnoTxRx---------------------------------- 508 509void mouthUnoTxRx(){ 510 511 Serial1.write(mouthOnOff); // send a byte with the value 45 512 if(Serial1.available() > 0){ 513 incomingMouthByte = Serial1.read(); // read the incoming byte: 514 } 515} 516 517//--------------------------end mouthUnoTxRx -------------------------------------- 518//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 519//--------------------------begin headUnoTxRx -------------------------------------- 520 521// call slave1 arduino for data 522 523void headUnoTxRx(){ 524 Serial2.write(headOnOff); // send a byte with the value 45 525 if(Serial2.available() > 0){ 526 incomingHeadByte = Serial2.read(); // read the incoming byte: 527 } 528} 529 530// call slave2 arduino for data 531//--------------------------end headUnoTxRx -------------------------------------- 532 533//**************************************************************************************************** 534//**************************************************************************************************** 535 536//--------------------------begin tftDisplay code---------------------------------- 537void tftDisplay(){ 538 Point p = ts.getPoint(); 539 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 540 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 541 Tft.fillRectangle(0, 225, 60, 30, BLACK); 542 Tft.drawNumber((p.x), 0, 225, 3, GREEN); 543 Tft.fillRectangle(180, 225, 60, 30, BLACK); 544 Tft.drawNumber((p.y), 180, 225, 3, GREEN); 545 Tft.fillRectangle(100, 225, 60, 30, BLACK); 546 Tft.drawNumber((buttonPressed), 100, 225, 3, GREEN); 547 Tft.fillRectangle(70, 160, 60, 30, BLACK); 548 Tft.drawNumber((mouthOnOff), 70, 160, 3, GREEN); 549 Tft.fillRectangle(140, 160, 60, 30, BLACK); 550 Tft.drawNumber((headOnOff), 140, 160, 3, GREEN); 551 Tft.fillRectangle(120, 290, 60, 30, BLACK); 552 Tft.drawNumber((currentScreen), 120, 290, 3, GREEN); 553 554 555}// void tftDisplay 556//--------------------------end tftDisplay code------------------------------------ 557 558//**************************************************************************************************** 559//**************************************************************************************************** 560 561//-------------------------- begin mouth on off function -------------------------- 562//-------------------------- end mouth on off function -------------------------- 563 564//**************************************************************************************************** 565//**************************************************************************************************** 566 567//-------------------------- begin head on off function -------------------------- 568//-------------------------- end head on off function ------------------------- 569 570//**************************************************************************************************** 571//**************************************************************************************************** 572 573//-------------------------- begin serial display function -------------------------- 574void showStuff(){ 575 Serial.println("------/ last update /-------"); 576// Serial.println("------begin display-------"); 577 Serial.print("buttonPressed "); 578 Serial.println(buttonPressed); 579 Serial.print("x "); 580 Serial.println(x); 581 Serial.print("y "); 582 Serial.println(y); 583 Serial.print("z "); 584 Serial.println(z); 585 Serial.print("currentScreen "); 586 Serial.println(currentScreen); 587// Serial.println("-------end display--------"); 588 Serial.println(""); 589 Serial.println(""); 590 Serial.println(""); 591 } 592//-------------------------- end serial display function ------------------------- 593 594 595//**************************************************************************************************** 596//**************************************************************************************************** 597 598//--------------------------- Primary screen maps -------------------------------- 599/* 600******** 601updates needed 602******** 6031 ditch the contrast 6042 ditch the brightness 6053 setup screen timeout 606 607 608 609 610screen 0000 A)Home 611 screen 0001 a)settings 612 screen 0011 -brightness 613 screen 0011 -contrast 614 screen 0011 -screen lock time out 615 screen 0001 b)sensor monitors 616 screen 0021 -pir 617 screen 0121 *report pir detection 618 screen 0021 -sound 619 screen 0221 *sense alexa sound 620 screen 0221 *sense graves sound 621 screen 0221 *report mouth servo position 622 screen 0221 *adjust sensitivity? 623 screen 0021 -head potentiometer 624 screen 0021 -bluetooth 625 screen 0001 c)bluetooth 626 screen 0031 -on 627 screen 0031 -off 628 screen 0031 -monitor 629screen 0000 B)Mouth Control 630 screen 0002 a)test button 631 screen 0012 -open 632 screen 0012 -close 633 screen 0012 -push button chicken switch 634 screen 0002 b)sound sensors on/off 635 screen 0022 -alexa sense 636 screen 0122 *on 637 screen 0122 *off 638 screen 0122 *monitor sensor 639 screen 0022 -graves sense 640 screen 0222 *on 641 screen 0222 *off 642 screen 0222 *monitor sensors 643 screen 0002 c)sound sensor status 644 screen 0032 -alexa 645 screen 0032 -graves 646screen 0000 C)Head Control 647 screen 0003 a)pir on/off 648 screen 0013 -on 649 screen 0013 -off 650 screen 0013 -sensor 651 screen 0003 b)manual point 652 screen 0023 -slider 653*/ 654//**************************************************************************************************** 655//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 656//**************************************************************************************************** 657//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 658//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 659//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 660//**************************************************************************************************** 661//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 662//**************************************************************************************************** 663 664//-------------------------- begin callScreen function ------------------------- 665//-------------------------- begin callScreen function ------------------------- 666//-------------------------- begin callScreen function ------------------------- 667//-------------------------- begin callScreen function ------------------------- 668//-------------------------- begin callScreen function ------------------------- 669//-------------------------- begin callScreen function ------------------------- 670//-------------------------- begin callScreen function ------------------------- 671//-------------------------- begin callScreen function ------------------------- 672//-------------------------- begin callScreen function ------------------------- 673//-------------------------- begin callScreen function ------------------------- 674//-------------------------- begin callScreen function ------------------------- 675 676int callScreen(){ 677 Tft.fillRectangle(0, 0, 240, 320, BLACK); 678 679//<><><><><><><><><><><><><><><><><><><><><><><><> 680//<><><><><><><><> begin screen 0000 master <><><><><><><><> 681//<><><><><><><><><><><><><><><><><><><><><><><><> 682if(currentScreen == 0){ 683 // " " 684 Tft.drawString("GRAVES",0,5,4, GREEN); 685 Tft.drawString("INTERFACE",10,50,4,GREEN); 686 Tft.drawString("Home", 80,130, 3, GREEN); 687 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 688 Tft.drawString("Head Control", 10, 260, 3, GREEN); 689} 690//<><><><><><><><><><><><><><><><><><><><><><><><> 691//<><><><><><><><> end screen 0000 master <><><><><><><><><> 692//<><><><><><><><><><><><><><><><><><><><><><><><> 693 694//<><><><><><><><><><><><><><><><><><><><><><><><> 695//<><><><><><><><> begin screen 0001 <><><><><><><><> 696//<><><><><><><><><><><><><><><><><><><><><><><><> 697 if(currentScreen == 1){ 698 // " " 699 Tft.drawString("MEGA 2560",00,5,4,BLUE); 700 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 701 Tft.drawString("Settings", 10,130, 3, BLUE); 702 Tft.drawString("Sensors", 20, 195, 3, BLUE); 703 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 704 Tft.drawString("<", 0, 160, 3, GREEN); // back button 705} 706//<><><><><><><><><><><><><><><><><><><><><><><><> 707//<><><><><><><><> end screen 0001 <><><><><><><><><> 708//<><><><><><><><><><><><><><><><><><><><><><><><> 709 710//<><><><><><><><><><><><><><><><><><><><><><><><> 711//<><><><><><><><> begin screen 0011 <><><><><><><><> 712//<><><><><><><><><><><><><><><><><><><><><><><><> 713 if(currentScreen == 11){ 714 // " " 715 Tft.drawString("MEGA 2560",00,5,4,BLUE); 716 Tft.drawString("SETTINGS",10,50,4,YELLOW); 717 Tft.drawString("Brightness", 80,130, 3, BLUE); 718 Tft.drawString("Contrast", 05, 195, 3, GREEN); 719 Tft.drawString("Timeout", 10, 260, 3, GREEN); 720 Tft.drawString("<", 0, 160, 3, GREEN); // back button 721} 722 723//<><><><><><><><><><><><><><><><><><><><><><><><> 724//<><><><><><><><> end screen 0011 <><><><><><><><><> 725//<><><><><><><><><><><><><><><><><><><><><><><><> 726 727//<><><><><><><><><><><><><><><><><><><><><><><><> 728//<><><><><><><><> begin screen 0021 <><><><><><><><> 729//<><><><><><><><><><><><><><><><><><><><><><><><> 730 if(currentScreen == 21){ 731 // " " 732 Tft.drawString("MEGA 2560",00,5,4,BLUE); 733 Tft.drawString("SENSORS",10,50,4,YELLOW); 734 Tft.drawString("PIR Array", 80,130, 3, BLUE); 735 Tft.drawString("Sound", 05, 195, 3, GREEN); 736 Tft.drawString("Head Position", 10, 260, 3, GREEN); 737 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 738 Tft.drawString("<", 0, 160, 3, GREEN); // back button 739} 740//<><><><><><><><><><><><><><><><><><><><><><><><> 741//<><><><><><><><> end screen 0021 <><><><><><><><><> 742//<><><><><><><><><><><><><><><><><><><><><><><><> 743 744//<><><><><><><><><><><><><><><><><><><><><><><><> 745//<><><><><><><><> begin screen 0121 <><><><><><><><> 746//<><><><><><><><><><><><><><><><><><><><><><><><> 747 if(currentScreen == 121){ 748 // " " 749 Tft.drawString("PIR",0,5,4,BLUE); 750 Tft.drawString("ARRAY",10,50,4,YELLOW); 751 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 752 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 753 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 754 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 755 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 756 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 757 Tft.drawString("<", 0, 160, 3, GREEN); // back button 758} 759//<><><><><><><><><><><><><><><><><><><><><><><><> 760//<><><><><><><><> end screen 0121 <><><><><><><><><> 761//<><><><><><><><><><><><><><><><><><><><><><><><> 762 763//<><><><><><><><><><><><><><><><><><><><><><><><> 764//<><><><><><><><> begin screen 0221 <><><><><><><><> 765//<><><><><><><><><><><><><><><><><><><><><><><><> 766 if(currentScreen == 221){ 767 // " " 768 Tft.drawString("SOUND",0,5,4,BLUE); 769 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 770 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 771 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 772 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 773 Tft.drawString("<", 0, 160, 3, GREEN); // back button 774} 775//<><><><><><><><><><><><><><><><><><><><><><><><> 776//<><><><><><><><> end screen 0221 <><><><><><><><><> 777//<><><><><><><><><><><><><><><><><><><><><><><><> 778 779//<><><><><><><><><><><><><><><><><><><><><><><><> 780//<><><><><><><><> begin screen 0031 <><><><><><><><> 781//<><><><><><><><><><><><><><><><><><><><><><><><> 782 if(currentScreen == 31){ 783 // " " 784 Tft.drawString("Bluetooth",0,5,4,BLUE); 785 Tft.drawString("Control",10,50,4,YELLOW); 786 Tft.drawString("On", 80,130, 3, BLUE); 787 Tft.drawString("Off", 05, 195, 3, GREEN); 788 Tft.drawString("Monitor", 10, 260, 3, GREEN); 789 Tft.drawString("<", 0, 160, 3, GREEN); // back button 790} 791//<><><><><><><><><><><><><><><><><><><><><><><><> 792//<><><><><><><><> end screen 0031 <><><><><><><><><> 793//<><><><><><><><><><><><><><><><><><><><><><><><> 794 795//<><><><><><><><><><><><><><><><><><><><><><><><> 796//<><><><><><><><> begin screen 0002 <><><><><><><><> 797//<><><><><><><><><><><><><><><><><><><><><><><><> 798 if(currentScreen == 2){ 799 // " " 800 Tft.drawString("Mouth",0,5,4,BLUE); 801 Tft.drawString("Control",10,50,4,YELLOW); 802 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 803 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 804 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 805 Tft.drawString("<", 0, 160, 3, GREEN); // back button 806 } 807//<><><><><><><><><><><><><><><><><><><><><><><><> 808//<><><><><><><><> end screen 0002 <><><><><><><><><> 809//<><><><><><><><><><><><><><><><><><><><><><><><> 810 811 812//<><><><><><><><><><><><><><><><><><><><><><><><> 813//<><><><><><><><> begin screen 0012 <><><><><><><><> 814//<><><><><><><><><><><><><><><><><><><><><><><><> 815 if(currentScreen == 12){ 816 // " " 817 Tft.drawString("Jaw Test",0,5,4,BLUE); 818 Tft.drawString("Operations",10,50,4,YELLOW); 819 Tft.drawString("Open", 80,130, 3, BLUE); 820 Tft.drawString("Close", 05, 195, 3, GREEN); 821 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 822 Tft.drawString("<", 0, 160, 3, GREEN); // back button 823} 824//<><><><><><><><><><><><><><><><><><><><><><><><> 825//<><><><><><><><> end screen 0012 <><><><><><><><><> 826//<><><><><><><><><><><><><><><><><><><><><><><><> 827 828 829//<><><><><><><><><><><><><><><><><><><><><><><><> 830//<><><><><><><><> begin screen 0022 <><><><><><><><> 831//<><><><><><><><><><><><><><><><><><><><><><><><> 832 if(currentScreen == 22){ 833 // " " 834 Tft.drawString("Sound",0,5,4,BLUE); 835 Tft.drawString("Sensors",10,50,4,YELLOW); 836 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 837 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 838 Tft.drawString("Monitor", 10, 260, 3, GREEN); 839 Tft.drawString("<", 0, 160, 3, GREEN); // back button 840} 841//<><><><><><><><><><><><><><><><><><><><><><><><> 842//<><><><><><><><> end screen 0022 <><><><><><><><><> 843//<><><><><><><><><><><><><><><><><><><><><><><><> 844 845 846 847//<><><><><><><><><><><><><><><><><><><><><><><><> 848//<><><><><><><><> begin screen 0122 <><><><><><><><> 849//<><><><><><><><><><><><><><><><><><><><><><><><> 850 if(currentScreen == 122){ 851 // " " 852 Tft.drawString("Alexa Sense",0,5,4,BLUE); 853 Tft.drawString("Operations",10,50,4,YELLOW); 854 Tft.drawString("On", 120, 130, 3, GREEN); 855 Tft.drawString("Off", 115, 195, 3, RED); 856 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 857 Tft.drawString("<", 0, 160, 3, GREEN); // back button 858} 859//<><><><><><><><><><><><><><><><><><><><><><><><> 860//<><><><><><><><> end screen 0122 <><><><><><><><><> 861//<><><><><><><><><><><><><><><><><><><><><><><><> 862 863//<><><><><><><><><><><><><><><><><><><><><><><><> 864//<><><><><><><><> begin screen 0222 <><><><><><><><> 865//<><><><><><><><><><><><><><><><><><><><><><><><> 866 if(currentScreen == 222){ 867 // " " 868 Tft.drawString("Graves Sense",0,5,4,BLUE); 869 Tft.drawString("Operations",10,50,4,YELLOW); 870 Tft.drawString("On", 120, 130, 3, GREEN); 871 Tft.drawString("Off", 115, 195, 3, RED); 872 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 873 Tft.drawString("<", 0, 160, 3, GREEN); // back button 874} 875//<><><><><><><><><><><><><><><><><><><><><><><><> 876//<><><><><><><><> end screen 0222 <><><><><><><><><> 877//<><><><><><><><><><><><><><><><><><><><><><><><> 878 879//<><><><><><><><><><><><><><><><><><><><><><><><> 880//<><><><><><><><> begin screen 0032 <><><><><><><><> 881//<><><><><><><><><><><><><><><><><><><><><><><><> 882 if(currentScreen == 32){ 883 // " " 884 Tft.drawString("Sound Sense",0,5,4,BLUE); 885 Tft.drawString("Monitors",10,50,4,YELLOW); 886 Tft.drawString("Alexa", 80,130, 3, BLUE); 887 Tft.drawString("Graves", 05, 195, 3, GREEN); 888 Tft.drawString("<", 0, 160, 3, GREEN); // back button 889} 890//<><><><><><><><><><><><><><><><><><><><><><><><> 891//<><><><><><><><> end screen 0032 <><><><><><><><><> 892//<><><><><><><><><><><><><><><><><><><><><><><><> 893 894//<><><><><><><><><><><><><><><><><><><><><><><><> 895//<><><><><><><><> begin screen 0003 <><><><><><><><> 896//<><><><><><><><><><><><><><><><><><><><><><><><> 897 if(currentScreen == 3){ 898 // " " 899 Tft.drawString("Head Control",0,5,4,BLUE); 900 Tft.drawString("Operations",10,50,4,YELLOW); 901 Tft.drawString("PIR Array", 80,130, 3, BLUE); 902 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 903 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 904 Tft.drawString("<", 0, 160, 3, GREEN); // back button 905} 906//<><><><><><><><><><><><><><><><><><><><><><><><> 907//<><><><><><><><> end screen 0003 <><><><><><><><><> 908//<><><><><><><><><><><><><><><><><><><><><><><><> 909 910//<><><><><><><><><><><><><><><><><><><><><><><><> 911//<><><><><><><><> begin screen 0013 <><><><><><><><> 912//<><><><><><><><><><><><><><><><><><><><><><><><> 913 if(currentScreen == 13){ 914 // " " 915 Tft.drawString("PIR Control",0,5,4,BLUE); 916 Tft.drawString("Operations",10,50,4,YELLOW); 917 Tft.drawString("On", 80,130, 3, BLUE); 918 Tft.drawString("Off", 05, 195, 3, GREEN); 919 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 920 Tft.drawString("<", 0, 160, 3, GREEN); // back button 921} 922//<><><><><><><><><><><><><><><><><><><><><><><><> 923//<><><><><><><><> end screen 0013 <><><><><><><><><> 924//<><><><><><><><><><><><><><><><><><><><><><><><> 925 926//<><><><><><><><><><><><><><><><><><><><><><><><> 927//<><><><><><><><> begin screen 0023 <><><><><><><><> 928//<><><><><><><><><><><><><><><><><><><><><><><><> 929 if(currentScreen == 23){ 930 // " " 931 Tft.drawString("Graves Head",0,5,3,BLUE); 932 Tft.drawString("Operations",10,50,3,YELLOW); 933 Tft.drawString("On", 120, 130, 3, GREEN); 934 Tft.drawString("Off", 115, 195, 3, RED); 935// Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 936 Tft.drawString("<", 0, 160, 3, GREEN); // back button 937} 938//<><><><><><><><><><><><><><><><><><><><><><><><> 939//<><><><><><><><> end screen 0023 <><><><><><><><><> 940//<><><><><><><><><><><><><><><><><><><><><><><><> 941 942 943//<><><><><><><><><><><><><><><><><><><><><><><><> 944//<><><><><><><><> begin screen 0422 <><><><><><><><> 945//<><><><><><><><><><><><><><><><><><><><><><><><> 946 if(currentScreen == 422){ 947 // " " 948 Tft.drawString("Command Sent",0,5,3,BLUE); 949 Tft.drawString("Press Back to",0,55,3,YELLOW); 950 Tft.drawString("Contiue", 50,105, 3, BLUE); 951 Tft.drawString("<", 0, 160, 3, GREEN); // back button 952} 953//<><><><><><><><><><><><><><><><><><><><><><><><> 954//<><><><><><><><> end screen 0422 <><><><><><><><><> 955//<><><><><><><><><><><><><><><><><><><><><><><><> 956 957 958////<><><><><><><><><><><><><><><><><><><><><><><><> 959////<><><><><><><><> begin screen lost <><><><><><><><> 960////<><><><><><><><><><><><><><><><><><><><><><><><> 961// else if(currentScreen){ 962// // " " 963// Tft.drawString("Screen not",0,5,3,BLUE); 964// Tft.drawString("found. Please",40,50,3,YELLOW); 965// Tft.drawString("use the back", 80,130, 3, BLUE); 966// Tft.drawString("button to", 05, 195, 3, GREEN); 967// Tft.drawString("return to fun", 10, 260, 3, GREEN); 968// Tft.drawString("<", 0, 160, 3, GREEN); // back button 969//} 970////<><><><><><><><><><><><><><><><><><><><><><><><> 971////<><><><><><><><> end screen lost <><><><><><><><><> 972////<><><><><><><><><><><><><><><><><><><><><><><><> 973 974}// callScreen 975//-------------------------- end callScreen function ------------------------- 976//-------------------------- end callScreen function ------------------------- 977//-------------------------- end callScreen function ------------------------- 978//-------------------------- end callScreen function ------------------------- 979//-------------------------- end callScreen function ------------------------- 980//-------------------------- end callScreen function ------------------------- 981//-------------------------- end callScreen function ------------------------- 982//-------------------------- end callScreen function ------------------------- 983//-------------------------- end callScreen function ------------------------- 984//-------------------------- end callScreen function ------------------------- 985//-------------------------- end callScreen function ------------------------- 986//-------------------------- end callScreen function ------------------------- 987//-------------------------- end callScreen function ------------------------- 988 989 990//**************************************************************************************************** 991//**************************************************************************************************** 992 993 994 995 996 997 998 999//**************************************************************************************************** 1000//**************************************************************************************************** 1001 1002// fin
Torture works!
c_cpp
And by that, I mean I tortured myself for days trying to get the mega to talk to the uno... then to get the uno to listen... then to get the uno to get the right message without changing it all around just to f with me... then to get the uno to talk back... then to get the mega to listen and understand. it all comes down to two major headaches. by trying to shortcut some intermediate programming, a whole of problems opens up for folks with crap knowledge so far like me. Timing a delay to wait for a response and getting the character data type to work around ascii tables makes my brain hurt
1/* 2last edit thursday oct 18 2018 3working on serial coms 4 5 6gravesmegamaster 7 8graves project 9arduino MEGA 2650 10Master 11coded from scratch by wylie jones 12wyliejones@gmail.com 13 14Graves multi arduino build 10/2018 15Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 16two arduino uno's 17slave1 arduino uno to sense sound from graves and echo dot to control mouth 18slave2 arduino uno to control passive sensor array and head servo 19 20sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 21 22 analogue pin speaker + 23 \ / (red from speaker) 24 \ / 25 \ / 26 *--------[=]-----------*---------[=]----------* 27 | resistor \ resistor | 28 | \ | 29 |(red with white) \ |to arduino ground (black with white) 30to arduino 5v+ speaker - 31 (black from speaker) 32 33*/ 34//end notes 35//end notes 36//end notes 37//end notes 38//end notes 39//end notes 40 41 42//********************************************************* 43//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 44//********************************************************* 45 46 47//begin declarations 48//begin declarations 49//begin declarations 50//begin declarations 51//begin declarations 52//begin declarations 53//begin declarations 54 55//#include <TFT.h> 56//#include <Servo.h> 57//#include <stdint.h> 58//#include <SD.h> 59#include <TFTv2.h> 60#include <SPI.h> 61#include <SeeedTouchScreen.h> 62//#include <Wire.h> 63 64//const int PIN_SD_CS = 4; // pin of sd card 65 66TouchScreen ts = TouchScreen(XP, YP, XM, YM); 67int zMax; // maximum pressure to detect 68int zMin; // minimum pressure to detect 69 70int buttonPressed; // stores which button was pressed 71unsigned long newButtonTime; // debounce 72unsigned long oldButtonTime; // debounce 73unsigned long buttonTimeDifference; // debounce 74unsigned long debounceTime; // debounce 75int buttonGroup; // sets kinds of buttons on screen 76 77int currentScreen; // identifies current screen by adding x y and z 78int x; // for ones 79int y; // for tens 80int z; // for hundreds 81 82unsigned long backlightTimer; // for backlight timeout 83int backLightState; // status of backlight 1 for on and 0 for off 84unsigned long backlightTimeDifference; 85unsigned long newBacklightTime; 86unsigned long oldBacklightTime; 87 88char incomingMouthByte; 89char outgoingMouthByte; 90int mouthOnOffNew; 91int mouthOnOffOld; 92int mouthOnOffDifference; 93int mouthOnOffAdjusted; // value adjusted by 48 for ascii 94 95char incomingHeadByte; 96char outgoingHeadByte; 97int headOnOffNew; 98int headOnOffOld; 99int headOnOffDifference; 100int headOnOffAdjusted; // value adjusted by 48 for ascii 101 102//end declarations 103//end declarations 104//end declarations 105//end declarations 106//end declarations 107//end declarations 108//end declarations 109//end declarations 110//end declarations 111 112//********************************************************* 113//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 114//********************************************************* 115 116// begin void setup 117// begin void setup 118// begin void setup 119// begin void setup 120// begin void setup 121// begin void setup 122// begin void setup 123// begin void setup 124// begin void setup 125// begin void setup 126// begin void setup 127void setup() { 128Serial.begin(9600); 129Serial1.begin(9600); 130Serial2.begin(9600); 131 oldButtonTime = millis(); 132 newButtonTime = millis(); 133 Tft.TFTinit(); // init TFT library 134 TFT_BL_ON; // turn on the background light 135 backLightState = 1; 136 x = 0; 137 y = 0; 138 z = 0; 139 buttonPressed = 4; 140 buttonGroup = 0; 141 142 incomingHeadByte = 1; 143 outgoingHeadByte = 1; // for a bit more talkative serial data 144 headOnOffNew = 1; // stores head state from serial connection 145 headOnOffOld = 1; // stores head state from serial connection 146 147 148 incomingMouthByte = 0; 149 outgoingMouthByte = 0; // for a bit more talkative serial data 150 mouthOnOffNew = 1; // stores mouth state from serial connection 151 mouthOnOffOld = 1; // stores mouth state from serial connection 152 153 154 //////////////////////////////// 155 //// manually set variables //// 156 //////////////////////////////// 157 158 debounceTime = 1000; // button debounce in milliseconds 159 zMax = 460; // maximum pressure to detect 160 zMin = 100; // minimum pressure to detect 161 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 162 163 164 currentScreen = 0; 165 callScreen(); 166 167} //void setup() 168// end void setup 169// end void setup 170// end void setup 171// end void setup 172// end void setup 173// end void setup 174// end void setup 175// end void setup 176 177//********************************************************* 178//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 179//********************************************************* 180 181// begin void loop 182// begin void loop 183// begin void loop 184// begin void loop 185// begin void loop 186// begin void loop 187// begin void loop 188// begin void loop 189// begin void loop 190// begin void loop 191// begin void loop 192// begin void loop 193// begin void loop 194// begin void loop 195 196void loop() { 197 198 tftBacklightTimeout(); // check time and turn off backlight 199 200 if(buttonGroup == 0){ // most regular pages 201 tftButtonGroup0(); // gather information from touch screen touches 202 buttonTimeDifference = newButtonTime - oldButtonTime; 203 if(debounceTime < buttonTimeDifference){ 204 whatScreen(); 205 callScreen(); 206 oldButtonTime = newButtonTime; 207 showStuff(); // serial prints 208 tftDisplay(); // display x y coordinates on tft display 209 } 210 } 211 if(buttonGroup == 1){ // on off buttons 212 tftButtonGroup1(); // gather information from touch screen touches 213 buttonTimeDifference = newButtonTime - oldButtonTime; 214 if(debounceTime < buttonTimeDifference){ 215 whatScreen(); 216 callScreen(); 217 oldButtonTime = newButtonTime; 218 showStuff(); // serial prints 219 tftDisplay(); // display x y coordinates on tft display 220 mouthUnoTxRx(); 221 } 222 } 223 if(buttonGroup == 2){ // head buttons 224 tftButtonGroup2(); // gather information from touch screen touches 225 buttonTimeDifference = newButtonTime - oldButtonTime; 226 if(debounceTime < buttonTimeDifference){ 227 whatScreen(); 228 callScreen(); 229 oldButtonTime = newButtonTime; 230 showStuff(); // serial prints 231 tftDisplay(); // display x y coordinates on tft display 232 headUnoTxRx(); 233 } 234 } 235 236 237} //void loop() 238 239// end of void loop 240// end of void loop 241// end of void loop 242// end of void loop 243// end of void loop 244// end of void loop 245// end of void loop 246// end of void loop 247// end of void loop 248// end of void loop 249// end of void loop 250// end of void loop 251// end of void loop 252// end of void loop 253// end of void loop 254 255//**************************************************************************************************** 256//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 257//**************************************************************************************************** 258///////////////////////////////////////////////////////////////////////////////////////////////////////// 259///////////////////////////////////////// functions /////////////////////////////////////////////////// 260///////////////////////////////////////////////////////////////////////////////////////////////////////// 261//**************************************************************************************************** 262//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 263//**************************************************************************************************** 264 265//--------------------------begin tftBacklightTimeout---------------------------------- 266void tftBacklightTimeout(){ 267 newBacklightTime = millis(); 268 if(backLightState = 0){ 269 backlightTimeDifference = newBacklightTime - oldBacklightTime; 270 if(backlightTimer > backlightTimeDifference){ 271 backlightTimeDifference = newBacklightTime - oldBacklightTime; 272 TFT_BL_ON; // turn on the background light 273 backLightState = 1; 274 oldBacklightTime = millis(); 275 } 276 } 277 if(backLightState = 1){ 278 backlightTimeDifference = newBacklightTime - oldBacklightTime; 279 if(backlightTimer < backlightTimeDifference){ 280 backlightTimeDifference = newBacklightTime - oldBacklightTime; 281 TFT_BL_OFF; // turn off the background light 282 backLightState = 0; 283 oldBacklightTime = millis(); 284 } 285 } 286} 287//--------------------------end tftBacklightTimeout---------------------------------- 288 289//**************************************************************************************************** 290//**************************************************************************************************** 291 292//--------------------------begin tftButtonGroup0---------------------------------- 293//--------------------------begin tftButtonGroup0---------------------------------- 294//--------------------------begin tftButtonGroup0---------------------------------- 295//--------------------------begin tftButtonGroup0---------------------------------- 296int tftButtonGroup0(){ 297 Point p = ts.getPoint(); 298 if(zMin<p.z && p.z<zMax){ 299 TFT_BL_ON; // turn on the background light 300 backLightState = 1; 301 oldBacklightTime = millis(); 302 newButtonTime = millis(); 303 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 304 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 305//Button 1 306 if(75<p.x && p.x<140){ 307 if(100<p.y && p.y<164){ 308 buttonPressed = 1; 309 } 310//Button 2 311 if(164<p.y && p.y<240){ 312 buttonPressed = 2; 313 } 314//Button 3 315 if(240<p.y && p.y<310){ 316 buttonPressed = 3; 317 } 318 } 319 } 320//Button 4 321 if(10<p.x && p.x<75){ 322 if(100<p.y && p.y<240){ 323 buttonPressed = 4; 324 } 325 } 326}//void tftButtonGroup0 327//--------------------------end tftButtonGroup0 code---------------------------------- 328//--------------------------end tftButtonGroup0 code---------------------------------- 329//--------------------------end tftButtonGroup0 code---------------------------------- 330//--------------------------end tftButtonGroup0 code---------------------------------- 331//--------------------------end tftButtonGroup0 code---------------------------------- 332//**************************************************************************************************** 333//**************************************************************************************************** 334 335//--------------------------begin tftButtonGroup1---------------------------------- 336//--------------------------begin tftButtonGroup1---------------------------------- 337//--------------------------begin tftButtonGroup1---------------------------------- 338//--------------------------begin tftButtonGroup1---------------------------------- 339int tftButtonGroup1(){ // for mouth 340buttonPressed = 0; 341 Point p = ts.getPoint(); 342 if(zMin<p.z && p.z<zMax){ 343 TFT_BL_ON; // turn on the background light 344 backLightState = 1; 345 oldBacklightTime = millis(); 346 newButtonTime = millis(); 347 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 348 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 349//Button 1 350 if(75<p.x && p.x<140){ 351 if(100<p.y && p.y<164){ 352 mouthOnOffNew = 1; // on 353 Serial.print("mouthOnOffNew set to "); 354 Serial.println(mouthOnOffNew); 355 } 356//Button 2 357 if(164<p.y && p.y<240){ 358 mouthOnOffNew = 2; // off 359 Serial.print("mouthOnOffNew set to "); 360 Serial.println(mouthOnOffNew); 361 } 362//Button 3 363// if(240<p.y && p.y<310){ 364// buttonPressed = 3; 365// } 366 } 367 } 368//Button 4 369 if(10<p.x && p.x<75){ 370 if(100<p.y && p.y<240){ 371 buttonPressed = 4; 372 buttonGroup = 0; 373 } 374 } 375}//void tftButtonGroup1 376//--------------------------end tftButtonGroup1 code---------------------------------- 377//--------------------------end tftButtonGroup1 code---------------------------------- 378//--------------------------end tftButtonGroup1 code---------------------------------- 379//--------------------------end tftButtonGroup1 code---------------------------------- 380//--------------------------end tftButtonGroup1 code---------------------------------- 381//**************************************************************************************************** 382//**************************************************************************************************** 383 384//--------------------------begin tftButtonGroup2---------------------------------- 385//--------------------------begin tftButtonGroup2---------------------------------- 386//--------------------------begin tftButtonGroup2---------------------------------- 387//--------------------------begin tftButtonGroup2---------------------------------- 388int tftButtonGroup2(){ // for mouth 389buttonPressed = 0; 390 Point p = ts.getPoint(); 391 if(zMin<p.z && p.z<zMax){ 392 TFT_BL_ON; // turn on the background light 393 backLightState = 1; 394 oldBacklightTime = millis(); 395 newButtonTime = millis(); 396 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 397 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 398//Button 1 399 if(75<p.x && p.x<140){ 400 if(100<p.y && p.y<164){ 401 headOnOffNew = 1; // on 402 Serial.print("headOnOffNew set to "); 403 Serial.println(headOnOffNew); 404 } 405//Button 2 406 if(164<p.y && p.y<240){ 407 headOnOffNew = 2; // off 408 Serial.print("headOnOffNew set to "); 409 Serial.println(headOnOffNew); 410 } 411//Button 3 412// if(240<p.y && p.y<310){ 413// buttonPressed = 3; 414// } 415 } 416 } 417//Button 4 418 if(10<p.x && p.x<75){ 419 if(100<p.y && p.y<240){ 420 buttonPressed = 4; 421 buttonGroup = 0; 422 } 423 } 424}//void tftButtonGroup2 425//--------------------------end tftButtonGroup2 code---------------------------------- 426//--------------------------end tftButtonGroup2 code---------------------------------- 427//--------------------------end tftButtonGroup2 code---------------------------------- 428//--------------------------end tftButtonGroup2 code---------------------------------- 429//--------------------------end tftButtonGroup2 code---------------------------------- 430//**************************************************************************************************** 431//**************************************************************************************************** 432//-------------------------- begin whatScreen function ------------------------- 433//-------------------------- begin whatScreen function ------------------------- 434//-------------------------- begin whatScreen function ------------------------- 435//-------------------------- begin whatScreen function ------------------------- 436 437int whatScreen(){ 438 if(x == 0){ 439 if(buttonPressed == 1){ 440 x = x + 1; 441 Serial.println("x + 1"); 442 } 443 if(buttonPressed == 2){ 444 x = x + 2; 445 Serial.println("x + 2"); 446 } 447 if(buttonPressed == 3){ 448 x = x + 3; 449 Serial.println("x + 3"); 450 } 451 if(buttonPressed == 4){ 452 x = 0; 453 Serial.println("x = 0"); 454 } 455 if(buttonPressed == 5){ 456 x = 0; 457 y = 0; 458 z = 0; 459 Serial.println("xyz all 0"); 460 } 461 } 462 else if(x >> 0){ 463 if(y == 0){ 464 if(buttonPressed == 1){ 465 y = y + 10; 466 Serial.println("y + 10"); 467 } 468 if(buttonPressed == 2){ 469 y = y + 20; 470 Serial.println("y + 20"); 471 } 472 if(buttonPressed == 3){ 473 y = y + 30; 474 Serial.println("y + 30"); 475 } 476 if(buttonPressed == 4){ 477 x = 0; 478 Serial.println("x = 0"); 479 } 480 if(buttonPressed == 5){ 481 x = 0; 482 y = 0; 483 z = 0; 484 Serial.println("xyz all 0"); 485 } 486 } 487 else if (y >> 0){ 488 if(buttonPressed == 1){ 489 z = z + 100; 490 Serial.println("z + 100"); 491 } 492 if(buttonPressed == 2){ 493 z = z + 200; 494 Serial.println("z + 200"); 495 } 496 if(buttonPressed == 3){ 497 z = z + 300; 498 Serial.println("z + 300"); 499 } 500 if(buttonPressed == 4){ 501 if(z == 0){ 502 y = 0; 503 Serial.println("y = 0"); 504 } 505 else if(z >> 0){ 506 z = 0; 507 Serial.println("z = 0"); 508 } 509 } 510 if(buttonPressed == 5){ 511 x = 0; 512 y = 0; 513 z = 0; 514 Serial.println("xyz all 0"); 515 } 516 }//y>0 517 }//x>0 518 currentScreen = z+y+x; 519 if(currentScreen == 122){ 520 buttonGroup=1; 521 } 522 if(currentScreen == 222){ 523 buttonGroup=1; 524 } 525 if(currentScreen == 23){ 526 buttonGroup=2; 527 } 528} 529//-------------------------- end whatScreen function ------------------------- 530//-------------------------- end whatScreen function ------------------------- 531//-------------------------- end whatScreen function ------------------------- 532//-------------------------- end whatScreen function ------------------------- 533//-------------------------- end whatScreen function ------------------------- 534 535//**************************************************************************************************** 536//**************************************************************************************************** 537 538//--------------------------begin mouthUnoTxRx---------------------------------- 539 540void mouthUnoTxRx(){ 541 if(mouthOnOffNew != mouthOnOffOld){ 542 Serial.println("starting txrx"); 543 delay(10); 544 if(mouthOnOffNew == 1){ 545 Serial.println("Starting tx"); 546 delay(10); 547 Serial1.flush(); 548 Serial1.write('1'); 549 delay(10); 550 mouthOnOffOld = 1; 551//begin rx 552 Serial.println("Starting rx"); 553 delay(4000); // tweak delay to accomodate uno 554 555 // use a serial available after flush funtion while or for loop or interrrupt or somethin 556 incomingMouthByte = Serial1.read(); 557 Serial1.flush(); 558 mouthOnOffAdjusted = incomingMouthByte; 559 Serial.print("mouthOnOffAdjusted should be 1: "); 560 Serial.println(mouthOnOffAdjusted); 561 } 562 if(mouthOnOffNew == 2){ 563 Serial.println("Starting tx"); 564 delay(10); 565 Serial1.flush(); 566 Serial1.write('2'); 567 delay(20); 568 mouthOnOffOld = 2; 569//begin rx 570 Serial.println("Starting rx"); 571 delay(3000); // tweak delay to accomodate uno 572 incomingMouthByte = Serial1.read(); 573 Serial1.flush(); 574 mouthOnOffAdjusted = incomingMouthByte; 575 Serial.print("mouthOnOffAdjusted should be 2: "); 576 Serial.println(mouthOnOffAdjusted); 577 } 578 else if(mouthOnOffAdjusted != 1 && mouthOnOffAdjusted != 2){ 579 Serial.println("error reply wasn't like expected"); 580 Serial.print("instead, the adjusted reply was"); 581 delay(6000); // tweak delay to accomodate uno 582 incomingMouthByte = Serial1.read(); 583 Serial1.flush(); 584 mouthOnOffAdjusted = incomingMouthByte; 585 Serial.print("mouthOnOffAdjusted: "); 586 Serial.println(mouthOnOffAdjusted); 587 } 588 } 589 else if(mouthOnOffOld = mouthOnOffNew){ 590 } 591 Serial.flush(); 592 Serial1.flush(); 593} 594 595//--------------------------end mouthUnoTxRx -------------------------------------- 596//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 597//--------------------------begin headUnoTxRx -------------------------------------- 598 599void headUnoTxRx(){ 600 if(headOnOffNew != headOnOffOld){ 601 if(headOnOffNew == 1){ 602 Serial2.write('1'); 603 Serial.write('1'); 604 headOnOffOld = 1; 605 delay(1000); 606 if(Serial2.available() > 0){ 607 incomingHeadByte = Serial2.read(); 608 headOnOffAdjusted = incomingHeadByte - 48; 609 if(headOnOffAdjusted == 1){ 610 Serial2.write('1'); 611 Serial.write('1'); 612 } 613 } 614 } 615 if(headOnOffNew == 2){ 616 Serial2.write('2'); 617 Serial.write('2'); 618 headOnOffOld = 2; 619 delay(1000); 620 if(Serial2.available() > 0){ 621 incomingHeadByte = Serial2.read(); 622 headOnOffAdjusted = incomingHeadByte - 48; 623 if(headOnOffAdjusted == 2){ 624 Serial2.write('2'); 625 Serial.write('2'); 626 } 627 } 628 } 629 } 630} 631//--------------------------end headUnoTxRx -------------------------------------- 632 633//**************************************************************************************************** 634//**************************************************************************************************** 635 636//--------------------------begin tftDisplay code---------------------------------- 637void tftDisplay(){ 638 Point p = ts.getPoint(); 639 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 640 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 641 642 Tft.fillRectangle(70, 100, 60, 30, BLACK); 643 Tft.drawNumber((buttonGroup), 70, 100, 3, GREEN); 644 Tft.fillRectangle(140, 100, 60, 30, BLACK); 645 Tft.drawNumber((mouthOnOffNew), 140, 100, 3, GREEN); 646 Tft.fillRectangle(160, 100, 60, 30, BLACK); 647 Tft.drawNumber((headOnOffNew), 160, 100, 3, GREEN); 648 Tft.fillRectangle(0, 225, 60, 30, BLACK); 649 Tft.drawNumber((p.x), 0, 225, 3, GREEN); 650 Tft.fillRectangle(180, 225, 60, 30, BLACK); 651 Tft.drawNumber((p.y), 180, 225, 3, GREEN); 652 Tft.fillRectangle(100, 225, 60, 30, BLACK); 653 Tft.drawNumber((buttonPressed), 100, 225, 3, GREEN); 654 Tft.fillRectangle(120, 290, 60, 30, BLACK); 655 Tft.drawNumber((currentScreen), 120, 290, 3, GREEN); 656 657 658}// void tftDisplay 659//--------------------------end tftDisplay code------------------------------------ 660 661//**************************************************************************************************** 662//**************************************************************************************************** 663 664//-------------------------- begin mouth on off function -------------------------- 665//-------------------------- end mouth on off function -------------------------- 666 667//**************************************************************************************************** 668//**************************************************************************************************** 669 670//-------------------------- begin head on off function -------------------------- 671//-------------------------- end head on off function ------------------------- 672 673//**************************************************************************************************** 674//**************************************************************************************************** 675 676//-------------------------- begin serial display function -------------------------- 677void showStuff(){ 678 Serial.println("------/ last update /-------"); 679// Serial.println("------begin display-------"); 680 Serial.print("buttonPressed "); 681 Serial.println(buttonPressed); 682 Serial.print("x "); 683 Serial.println(x); 684 Serial.print("y "); 685 Serial.println(y); 686 Serial.print("z "); 687 Serial.println(z); 688 Serial.print("currentScreen "); 689 Serial.println(currentScreen); 690// Serial.println("-------end display--------"); 691 Serial.println(""); 692 Serial.println(""); 693 Serial.println(""); 694 } 695//-------------------------- end serial display function ------------------------- 696 697 698//**************************************************************************************************** 699//**************************************************************************************************** 700 701//--------------------------- Primary screen maps -------------------------------- 702/* 703******** 704updates needed 705******** 7061 ditch the contrast 7072 ditch the brightness 7083 setup screen timeout 709 710 711 712 713screen 0000 A)Home 714 screen 0001 a)settings 715 screen 0011 -brightness 716 screen 0011 -contrast 717 screen 0011 -screen lock time out 718 screen 0001 b)sensor monitors 719 screen 0021 -pir 720 screen 0121 *report pir detection 721 screen 0021 -sound 722 screen 0221 *sense alexa sound 723 screen 0221 *sense graves sound 724 screen 0221 *report mouth servo position 725 screen 0221 *adjust sensitivity? 726 screen 0021 -head potentiometer 727 screen 0021 -bluetooth 728 screen 0001 c)bluetooth 729 screen 0031 -on 730 screen 0031 -off 731 screen 0031 -monitor 732screen 0000 B)Mouth Control 733 screen 0002 a)test button 734 screen 0012 -open 735 screen 0012 -close 736 screen 0012 -push button chicken switch 737 screen 0002 b)sound sensors on/off 738 screen 0022 -alexa sense 739 screen 0122 *on 740 screen 0122 *off 741 screen 0122 *monitor sensor 742 screen 0022 -graves sense 743 screen 0222 *on 744 screen 0222 *off 745 screen 0222 *monitor sensors 746 screen 0002 c)sound sensor status 747 screen 0032 -alexa 748 screen 0032 -graves 749screen 0000 C)Head Control 750 screen 0003 a)pir on/off 751 screen 0013 -on 752 screen 0013 -off 753 screen 0013 -sensor 754 screen 0003 b)manual point 755 screen 0023 -slider 756*/ 757//**************************************************************************************************** 758//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 759//**************************************************************************************************** 760//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 761//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 762//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 763//**************************************************************************************************** 764//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 765//**************************************************************************************************** 766 767//-------------------------- begin callScreen function ------------------------- 768//-------------------------- begin callScreen function ------------------------- 769//-------------------------- begin callScreen function ------------------------- 770//-------------------------- begin callScreen function ------------------------- 771//-------------------------- begin callScreen function ------------------------- 772//-------------------------- begin callScreen function ------------------------- 773//-------------------------- begin callScreen function ------------------------- 774//-------------------------- begin callScreen function ------------------------- 775//-------------------------- begin callScreen function ------------------------- 776//-------------------------- begin callScreen function ------------------------- 777//-------------------------- begin callScreen function ------------------------- 778 779int callScreen(){ 780 Tft.fillRectangle(0, 0, 240, 320, BLACK); 781 782//<><><><><><><><><><><><><><><><><><><><><><><><> 783//<><><><><><><><> begin screen 0000 master <><><><><><><><> 784//<><><><><><><><><><><><><><><><><><><><><><><><> 785if(currentScreen == 0){ 786 // " " 787 Tft.drawString("GRAVES",0,5,4, GREEN); 788 Tft.drawString("INTERFACE",10,50,4,GREEN); 789 Tft.drawString("Home", 80,130, 3, GREEN); 790 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 791 Tft.drawString("Head Control", 10, 260, 3, GREEN); 792} 793//<><><><><><><><><><><><><><><><><><><><><><><><> 794//<><><><><><><><> end screen 0000 master <><><><><><><><><> 795//<><><><><><><><><><><><><><><><><><><><><><><><> 796 797//<><><><><><><><><><><><><><><><><><><><><><><><> 798//<><><><><><><><> begin screen 0001 <><><><><><><><> 799//<><><><><><><><><><><><><><><><><><><><><><><><> 800 if(currentScreen == 1){ 801 // " " 802 Tft.drawString("MEGA 2560",00,5,4,BLUE); 803 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 804 Tft.drawString("Settings", 10,130, 3, BLUE); 805 Tft.drawString("Sensors", 20, 195, 3, BLUE); 806 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 807 Tft.drawString("<", 0, 160, 3, GREEN); // back button 808} 809//<><><><><><><><><><><><><><><><><><><><><><><><> 810//<><><><><><><><> end screen 0001 <><><><><><><><><> 811//<><><><><><><><><><><><><><><><><><><><><><><><> 812 813//<><><><><><><><><><><><><><><><><><><><><><><><> 814//<><><><><><><><> begin screen 0011 <><><><><><><><> 815//<><><><><><><><><><><><><><><><><><><><><><><><> 816 if(currentScreen == 11){ 817 // " " 818 Tft.drawString("MEGA 2560",00,5,4,BLUE); 819 Tft.drawString("SETTINGS",10,50,4,YELLOW); 820 Tft.drawString("Brightness", 80,130, 3, BLUE); 821 Tft.drawString("Contrast", 05, 195, 3, GREEN); 822 Tft.drawString("Timeout", 10, 260, 3, GREEN); 823 Tft.drawString("<", 0, 160, 3, GREEN); // back button 824} 825 826//<><><><><><><><><><><><><><><><><><><><><><><><> 827//<><><><><><><><> end screen 0011 <><><><><><><><><> 828//<><><><><><><><><><><><><><><><><><><><><><><><> 829 830//<><><><><><><><><><><><><><><><><><><><><><><><> 831//<><><><><><><><> begin screen 0021 <><><><><><><><> 832//<><><><><><><><><><><><><><><><><><><><><><><><> 833 if(currentScreen == 21){ 834 // " " 835 Tft.drawString("MEGA 2560",00,5,4,BLUE); 836 Tft.drawString("SENSORS",10,50,4,YELLOW); 837 Tft.drawString("PIR Array", 80,130, 3, BLUE); 838 Tft.drawString("Sound", 05, 195, 3, GREEN); 839 Tft.drawString("Head Position", 10, 260, 3, GREEN); 840 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 841 Tft.drawString("<", 0, 160, 3, GREEN); // back button 842} 843//<><><><><><><><><><><><><><><><><><><><><><><><> 844//<><><><><><><><> end screen 0021 <><><><><><><><><> 845//<><><><><><><><><><><><><><><><><><><><><><><><> 846 847//<><><><><><><><><><><><><><><><><><><><><><><><> 848//<><><><><><><><> begin screen 0121 <><><><><><><><> 849//<><><><><><><><><><><><><><><><><><><><><><><><> 850 if(currentScreen == 121){ 851 // " " 852 Tft.drawString("PIR",0,5,4,BLUE); 853 Tft.drawString("ARRAY",10,50,4,YELLOW); 854 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 855 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 856 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 857 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 858 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 859 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 860 Tft.drawString("<", 0, 160, 3, GREEN); // back button 861} 862//<><><><><><><><><><><><><><><><><><><><><><><><> 863//<><><><><><><><> end screen 0121 <><><><><><><><><> 864//<><><><><><><><><><><><><><><><><><><><><><><><> 865 866//<><><><><><><><><><><><><><><><><><><><><><><><> 867//<><><><><><><><> begin screen 0221 <><><><><><><><> 868//<><><><><><><><><><><><><><><><><><><><><><><><> 869 if(currentScreen == 221){ 870 // " " 871 Tft.drawString("SOUND",0,5,4,BLUE); 872 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 873 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 874 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 875 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 876 Tft.drawString("<", 0, 160, 3, GREEN); // back button 877} 878//<><><><><><><><><><><><><><><><><><><><><><><><> 879//<><><><><><><><> end screen 0221 <><><><><><><><><> 880//<><><><><><><><><><><><><><><><><><><><><><><><> 881 882//<><><><><><><><><><><><><><><><><><><><><><><><> 883//<><><><><><><><> begin screen 0031 <><><><><><><><> 884//<><><><><><><><><><><><><><><><><><><><><><><><> 885 if(currentScreen == 31){ 886 // " " 887 Tft.drawString("Bluetooth",0,5,4,BLUE); 888 Tft.drawString("Control",10,50,4,YELLOW); 889 Tft.drawString("On", 80,130, 3, BLUE); 890 Tft.drawString("Off", 05, 195, 3, GREEN); 891 Tft.drawString("Monitor", 10, 260, 3, GREEN); 892 Tft.drawString("<", 0, 160, 3, GREEN); // back button 893} 894//<><><><><><><><><><><><><><><><><><><><><><><><> 895//<><><><><><><><> end screen 0031 <><><><><><><><><> 896//<><><><><><><><><><><><><><><><><><><><><><><><> 897 898//<><><><><><><><><><><><><><><><><><><><><><><><> 899//<><><><><><><><> begin screen 0002 <><><><><><><><> 900//<><><><><><><><><><><><><><><><><><><><><><><><> 901 if(currentScreen == 2){ 902 // " " 903 Tft.drawString("Mouth",0,5,4,BLUE); 904 Tft.drawString("Control",10,50,4,YELLOW); 905 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 906 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 907 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 908 Tft.drawString("<", 0, 160, 3, GREEN); // back button 909 } 910//<><><><><><><><><><><><><><><><><><><><><><><><> 911//<><><><><><><><> end screen 0002 <><><><><><><><><> 912//<><><><><><><><><><><><><><><><><><><><><><><><> 913 914 915//<><><><><><><><><><><><><><><><><><><><><><><><> 916//<><><><><><><><> begin screen 0012 <><><><><><><><> 917//<><><><><><><><><><><><><><><><><><><><><><><><> 918 if(currentScreen == 12){ 919 // " " 920 Tft.drawString("Jaw Test",0,5,4,BLUE); 921 Tft.drawString("Operations",10,50,4,YELLOW); 922 Tft.drawString("Open", 80,130, 3, BLUE); 923 Tft.drawString("Close", 05, 195, 3, GREEN); 924 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 925 Tft.drawString("<", 0, 160, 3, GREEN); // back button 926} 927//<><><><><><><><><><><><><><><><><><><><><><><><> 928//<><><><><><><><> end screen 0012 <><><><><><><><><> 929//<><><><><><><><><><><><><><><><><><><><><><><><> 930 931 932//<><><><><><><><><><><><><><><><><><><><><><><><> 933//<><><><><><><><> begin screen 0022 <><><><><><><><> 934//<><><><><><><><><><><><><><><><><><><><><><><><> 935 if(currentScreen == 22){ 936 // " " 937 Tft.drawString("Sound",0,5,4,BLUE); 938 Tft.drawString("Sensors",10,50,4,YELLOW); 939 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 940 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 941 Tft.drawString("Monitor", 10, 260, 3, GREEN); 942 Tft.drawString("<", 0, 160, 3, GREEN); // back button 943} 944//<><><><><><><><><><><><><><><><><><><><><><><><> 945//<><><><><><><><> end screen 0022 <><><><><><><><><> 946//<><><><><><><><><><><><><><><><><><><><><><><><> 947 948 949 950//<><><><><><><><><><><><><><><><><><><><><><><><> 951//<><><><><><><><> begin screen 0122 <><><><><><><><> 952//<><><><><><><><><><><><><><><><><><><><><><><><> 953 if(currentScreen == 122){ 954 // " " 955 Tft.drawString("Alexa Sense",0,5,4,BLUE); 956 Tft.drawString("Operations",10,50,4,YELLOW); 957 Tft.drawString("On", 120, 130, 3, GREEN); 958 Tft.drawString("Off", 115, 195, 3, RED); 959 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 960 Tft.drawString("<", 0, 160, 3, GREEN); // back button 961} 962//<><><><><><><><><><><><><><><><><><><><><><><><> 963//<><><><><><><><> end screen 0122 <><><><><><><><><> 964//<><><><><><><><><><><><><><><><><><><><><><><><> 965 966//<><><><><><><><><><><><><><><><><><><><><><><><> 967//<><><><><><><><> begin screen 0222 <><><><><><><><> 968//<><><><><><><><><><><><><><><><><><><><><><><><> 969 if(currentScreen == 222){ 970 // " " 971 Tft.drawString("Graves Sense",0,5,4,BLUE); 972 Tft.drawString("Operations",10,50,4,YELLOW); 973 Tft.drawString("On", 120, 130, 3, GREEN); 974 Tft.drawString("Off", 115, 195, 3, RED); 975 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 976 Tft.drawString("<", 0, 160, 3, GREEN); // back button 977} 978//<><><><><><><><><><><><><><><><><><><><><><><><> 979//<><><><><><><><> end screen 0222 <><><><><><><><><> 980//<><><><><><><><><><><><><><><><><><><><><><><><> 981 982//<><><><><><><><><><><><><><><><><><><><><><><><> 983//<><><><><><><><> begin screen 0032 <><><><><><><><> 984//<><><><><><><><><><><><><><><><><><><><><><><><> 985 if(currentScreen == 32){ 986 // " " 987 Tft.drawString("Sound Sense",0,5,4,BLUE); 988 Tft.drawString("Monitors",10,50,4,YELLOW); 989 Tft.drawString("Alexa", 80,130, 3, BLUE); 990 Tft.drawString("Graves", 05, 195, 3, GREEN); 991 Tft.drawString("<", 0, 160, 3, GREEN); // back button 992} 993//<><><><><><><><><><><><><><><><><><><><><><><><> 994//<><><><><><><><> end screen 0032 <><><><><><><><><> 995//<><><><><><><><><><><><><><><><><><><><><><><><> 996 997//<><><><><><><><><><><><><><><><><><><><><><><><> 998//<><><><><><><><> begin screen 0003 <><><><><><><><> 999//<><><><><><><><><><><><><><><><><><><><><><><><> 1000 if(currentScreen == 3){ 1001 // " " 1002 Tft.drawString("Head Control",0,5,4,BLUE); 1003 Tft.drawString("Operations",10,50,4,YELLOW); 1004 Tft.drawString("PIR Array", 80,130, 3, BLUE); 1005 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 1006 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 1007 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1008} 1009//<><><><><><><><><><><><><><><><><><><><><><><><> 1010//<><><><><><><><> end screen 0003 <><><><><><><><><> 1011//<><><><><><><><><><><><><><><><><><><><><><><><> 1012 1013//<><><><><><><><><><><><><><><><><><><><><><><><> 1014//<><><><><><><><> begin screen 0013 <><><><><><><><> 1015//<><><><><><><><><><><><><><><><><><><><><><><><> 1016 if(currentScreen == 13){ 1017 // " " 1018 Tft.drawString("PIR Control",0,5,4,BLUE); 1019 Tft.drawString("Operations",10,50,4,YELLOW); 1020 Tft.drawString("On", 80,130, 3, BLUE); 1021 Tft.drawString("Off", 05, 195, 3, GREEN); 1022 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 1023 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1024} 1025//<><><><><><><><><><><><><><><><><><><><><><><><> 1026//<><><><><><><><> end screen 0013 <><><><><><><><><> 1027//<><><><><><><><><><><><><><><><><><><><><><><><> 1028 1029//<><><><><><><><><><><><><><><><><><><><><><><><> 1030//<><><><><><><><> begin screen 0023 <><><><><><><><> 1031//<><><><><><><><><><><><><><><><><><><><><><><><> 1032 if(currentScreen == 23){ 1033 // " " 1034 Tft.drawString("Graves Head",0,5,3,BLUE); 1035 Tft.drawString("Operations",10,50,3,YELLOW); 1036 Tft.drawString("On", 120, 130, 3, GREEN); 1037 Tft.drawString("Off", 115, 195, 3, RED); 1038// Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1039 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1040} 1041//<><><><><><><><><><><><><><><><><><><><><><><><> 1042//<><><><><><><><> end screen 0023 <><><><><><><><><> 1043//<><><><><><><><><><><><><><><><><><><><><><><><> 1044 1045 1046//<><><><><><><><><><><><><><><><><><><><><><><><> 1047//<><><><><><><><> begin screen 0422 <><><><><><><><> 1048//<><><><><><><><><><><><><><><><><><><><><><><><> 1049 if(currentScreen == 422){ 1050 // " " 1051 Tft.drawString("Command Sent",0,5,3,BLUE); 1052 Tft.drawString("Press Back to",0,55,3,YELLOW); 1053 Tft.drawString("Contiue", 50,105, 3, BLUE); 1054 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1055} 1056//<><><><><><><><><><><><><><><><><><><><><><><><> 1057//<><><><><><><><> end screen 0422 <><><><><><><><><> 1058//<><><><><><><><><><><><><><><><><><><><><><><><> 1059 1060 1061////<><><><><><><><><><><><><><><><><><><><><><><><> 1062////<><><><><><><><> begin screen lost <><><><><><><><> 1063////<><><><><><><><><><><><><><><><><><><><><><><><> 1064// else if(currentScreen){ 1065// // " " 1066// Tft.drawString("Screen not",0,5,3,BLUE); 1067// Tft.drawString("found. Please",40,50,3,YELLOW); 1068// Tft.drawString("use the back", 80,130, 3, BLUE); 1069// Tft.drawString("button to", 05, 195, 3, GREEN); 1070// Tft.drawString("return to fun", 10, 260, 3, GREEN); 1071// Tft.drawString("<", 0, 160, 3, GREEN); // back button 1072//} 1073////<><><><><><><><><><><><><><><><><><><><><><><><> 1074////<><><><><><><><> end screen lost <><><><><><><><><> 1075////<><><><><><><><><><><><><><><><><><><><><><><><> 1076 1077}// callScreen 1078//-------------------------- end callScreen function ------------------------- 1079//-------------------------- end callScreen function ------------------------- 1080//-------------------------- end callScreen function ------------------------- 1081//-------------------------- end callScreen function ------------------------- 1082//-------------------------- end callScreen function ------------------------- 1083//-------------------------- end callScreen function ------------------------- 1084//-------------------------- end callScreen function ------------------------- 1085//-------------------------- end callScreen function ------------------------- 1086//-------------------------- end callScreen function ------------------------- 1087//-------------------------- end callScreen function ------------------------- 1088//-------------------------- end callScreen function ------------------------- 1089//-------------------------- end callScreen function ------------------------- 1090//-------------------------- end callScreen function ------------------------- 1091 1092 1093//**************************************************************************************************** 1094//**************************************************************************************************** 1095 1096 1097 1098 1099 1100 1101 1102//**************************************************************************************************** 1103//**************************************************************************************************** 1104 1105// fin
draft 2
c_cpp
initial screen creation and menu build some tft tracking and display
1/* 2last edit sun oct 7 2018 3 4Graves multi arduino build 10/2018 5Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 6two arduino uno's 7slave1 arduino uno to sense sound from graves and echo dot to control mouth 8slave2 arduino uno to control passive sensor array and head servo 9 10sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 11 12 analogue pin speaker + 13 \ / (red from speaker) 14 \ / 15 \ / 16 *--------[=]-----------*---------[=]----------* 17 | resistor \ resistor | 18 | \ | 19 |(red with white) \ |to arduino ground (black with white) 20to arduino 5v+ speaker - 21 (black from speaker) 22 23*/ 24 25//#include <TFT.h> 26//#include <Servo.h> 27//#include <stdint.h> 28//#include <SD.h> 29#include <TFTv2.h> 30#include <SPI.h> 31#include <SeeedTouchScreen.h> 32 33//const int PIN_SD_CS = 4; // pin of sd card 34 35TouchScreen ts = TouchScreen(XP, YP, XM, YM); 36 37 38//********************************************************* 39//********************************************************* 40 41// begin void setup 42// begin void setup 43// begin void setup 44// begin void setup 45// begin void setup 46// begin void setup 47// begin void setup 48// begin void setup 49// begin void setup 50// begin void setup 51// begin void setup 52 53void setup() { 54 // need timer to track screen timeout 55 // set screen to on and let timer run to turn off 56 Tft.TFTinit(); // init TFT library 57 TFT_BL_ON; // turn on the background light 58 59screenMaster(); //calls function to draw title and menu items 60 61} //void setup() 62 63// end void setup 64// end void setup 65// end void setup 66// end void setup 67// end void setup 68// end void setup 69// end void setup 70// end void setup 71 72//********************************************************* 73//********************************************************* 74 75// begin void loop 76// begin void loop 77// begin void loop 78// begin void loop 79// begin void loop 80// begin void loop 81// begin void loop 82// begin void loop 83 84void loop() { 85 86 87//tftDetect(); // gather information from touch screen touches 88 89tftDisplay(); // display x y coordinates on tft display 90 91} //void loop() 92 93// end of void loop 94// end of void loop 95// end of void loop 96// end of void loop 97// end of void loop 98// end of void loop 99// end of void loop 100// end of void loop 101// end of void loop 102// end of void loop 103// end of void loop 104// end of void loop 105// end of void loop 106// end of void loop 107 108///////////////////////////////////////////////////////////////////////////////////////////////////////// 109////////////////////////////////////////// /////////////////////////////////////////////////// 110///////////////////////////////////////// functions /////////////////////////////////////////////////// 111//////////////////////////////////////// /////////////////////////////////////////////////// 112///////////////////////////////////////////////////////////////////////////////////////////////////////// 113 114//**************************************************************************************************** 115//**************************************************************************************************** 116//--------------------------begin TFT input code---------------------------------- 117void tftDetect(){ 118 // a point object holds x y and z coordinates 119 Point p = ts.getPoint(); 120 if(100<p.z && p.z<460){ // max and min z variable later? acts as debounce 121 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 122 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 123 }//if 124}//void tftDetect 125//--------------------------end TFT intput code---------------------------------- 126//**************************************************************************************************** 127//**************************************************************************************************** 128 129//--------------------------begin arduino master data fetch calls---------------------------------- 130// call slave1 arduino for data 131// call slave2 arduino for data 132//--------------------------end arduino master data fetch calls------------------------------------ 133 134//**************************************************************************************************** 135//**************************************************************************************************** 136 137//--------------------------begin TFT output code---------------------------------- 138void tftDisplay(){ 139 Point p = ts.getPoint(); 140 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 141 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 142// p.z = map(p.z, 0, 600, 100, 0); 143 144 if(100<p.z && p.z<460){ // max and min z variable later? acts as debounce 145 Tft.fillRectangle(0, 160, 60, 30, BLACK); 146 Tft.drawNumber((p.x), 0, 160, 3, GREEN); 147 Tft.fillRectangle(180, 160, 60, 30, BLACK); 148 Tft.drawNumber((p.y), 180, 160, 3, GREEN); 149 }//if 150}// void tftDisplay 151//--------------------------end TFT output code------------------------------------ 152 153//**************************************************************************************************** 154//**************************************************************************************************** 155 156//-------------------------- begin slave1 data fetch function -------------------------- 157//-------------------------- end slave1 data fetch function -------------------------- 158 159//**************************************************************************************************** 160//**************************************************************************************************** 161 162//-------------------------- begin slave2 data fetch function -------------------------- 163//-------------------------- end slave2 data fetch function ------------------------- 164 165//**************************************************************************************************** 166//**************************************************************************************************** 167 168 169//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 170//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 171//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 172//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 173//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 174/* 175background screen file names on sd card 176pipboybg.bmp 177pipboylocked.bmp 178tft2buttons.bmp 179tft3buttons.bmp 180*/ 181//**************************************************************************************************** 182//**************************************************************************************************** 183 184//--------------------------- Primary screen maps -------------------------------- 185/* 186 text size 3 can fit 13 characters 187 188screen 1 A)master 189screen 2 a)settings 190screen 2 -brightness 191screen 2 -contrast 192screen 2 -screen lock time out 193screen 3 b)sensor monitors 194screen 3 -pir 195screen 4 *report pir detection 196screen 4 *report head servo position 197screen 3 -sound 198screen 5 *sense alexa sound 199screen 5 *sense graves sound 200screen 5 *report mouth servo position 201screen 5 *adjust sensitivity? 202screen 3 c)bluetooth 203screen 6 -on 204screen 6 -off 205screen 6 -monitor 206 207screen 7 B)slave1 mouth servo 208screen 7 a)test button 209screen 8 -open 210screen 8 -close 211screen 8 -push button chicken switch 212screen 7 b)sound sensors on/off 213screen 9 -alexa sense 214screen 10 *on 215screen 10 *off 216screen 10 *monitor sensor 217screen 9 -graves sense 218screen 11 *on 219screen 11 *off 220screen 11 *monitor sensors 221screen 7 c)sound sensor status 222screen 12 -alexa 223screen 12 -graves 224 225screen 13 C)slave2 head servo 226screen 14 a)pir on/off 227screen 15 -on 228screen 15 -off 229screen 14 b)manual point 230screen 16 -slider 231*/ 232 233//<><><><><><><><><><><><><><><><><><><><><><><><> 234//<><><><><><><><> begin screen master <><><><><><><><> 235//<><><><><><><><><><><><><><><><><><><><><><><><> 236void screenMaster(){ 237 // " " 238 Tft.drawString("Undertaker",0,5,4,GREEN); 239 Tft.drawString("Interface",10,50,4,GREEN); 240 Tft.drawString("Home", 80,130, 3, GREEN); 241 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 242 Tft.drawString("Head Control", 10, 260, 3, GREEN); 243} 244//<><><><><><><><><><><><><><><><><><><><><><><><> 245//<><><><><><><><> end screen master <><><><><><><><><> 246//<><><><><><><><><><><><><><><><><><><><><><><><> 247 248//<><><><><><><><><><><><><><><><><><><><><><><><> 249//<><><><><><><><> begin screen 1 <><><><><><><><> 250//<><><><><><><><><><><><><><><><><><><><><><><><> 251 252//<><><><><><><><><><><><><><><><><><><><><><><><> 253//<><><><><><><><> end screen 1 <><><><><><><><><> 254//<><><><><><><><><><><><><><><><><><><><><><><><> 255 256 257//<><><><><><><><><><><><><><><><><><><><><><><><> 258//<><><><><><><><> begin screen 2 <><><><><><><><> 259//<><><><><><><><><><><><><><><><><><><><><><><><> 260 261 262//<><><><><><><><><><><><><><><><><><><><><><><><> 263//<><><><><><><><> end screen 2 <><><><><><><><><> 264//<><><><><><><><><><><><><><><><><><><><><><><><> 265 266 267 268//<><><><><><><><><><><><><><><><><><><><><><><><> 269//<><><><><><><><> begin screen 3 <><><><><><><><> 270//<><><><><><><><><><><><><><><><><><><><><><><><> 271 272 273//<><><><><><><><><><><><><><><><><><><><><><><><> 274//<><><><><><><><> end screen 3 <><><><><><><><><> 275//<><><><><><><><><><><><><><><><><><><><><><><><> 276 277 278//<><><><><><><><><><><><><><><><><><><><><><><><> 279//<><><><><><><><> begin screen 4 <><><><><><><><> 280//<><><><><><><><><><><><><><><><><><><><><><><><> 281 282 283//<><><><><><><><><><><><><><><><><><><><><><><><> 284//<><><><><><><><> end screen 4 <><><><><><><><><> 285//<><><><><><><><><><><><><><><><><><><><><><><><> 286 287 288//<><><><><><><><><><><><><><><><><><><><><><><><> 289//<><><><><><><><> begin screen 5 <><><><><><><><> 290//<><><><><><><><><><><><><><><><><><><><><><><><> 291 292 293//<><><><><><><><><><><><><><><><><><><><><><><><> 294//<><><><><><><><> end screen 5 <><><><><><><><><> 295//<><><><><><><><><><><><><><><><><><><><><><><><> 296 297 298 299//<><><><><><><><><><><><><><><><><><><><><><><><> 300//<><><><><><><><> begin screen 6 <><><><><><><><> 301//<><><><><><><><><><><><><><><><><><><><><><><><> 302 303 304//<><><><><><><><><><><><><><><><><><><><><><><><> 305//<><><><><><><><> end screen 6 <><><><><><><><><> 306//<><><><><><><><><><><><><><><><><><><><><><><><> 307 308 309//<><><><><><><><><><><><><><><><><><><><><><><><> 310//<><><><><><><><> begin screen 7 <><><><><><><><> 311//<><><><><><><><><><><><><><><><><><><><><><><><> 312 313 314//<><><><><><><><><><><><><><><><><><><><><><><><> 315//<><><><><><><><> end screen 7 <><><><><><><><><> 316//<><><><><><><><><><><><><><><><><><><><><><><><> 317 318 319//<><><><><><><><><><><><><><><><><><><><><><><><> 320//<><><><><><><><> begin screen 8 <><><><><><><><> 321//<><><><><><><><><><><><><><><><><><><><><><><><> 322 323 324//<><><><><><><><><><><><><><><><><><><><><><><><> 325//<><><><><><><><> end screen 8 <><><><><><><><><> 326//<><><><><><><><><><><><><><><><><><><><><><><><> 327 328 329 330//<><><><><><><><><><><><><><><><><><><><><><><><> 331//<><><><><><><><> begin screen 9 <><><><><><><><> 332//<><><><><><><><><><><><><><><><><><><><><><><><> 333 334 335//<><><><><><><><><><><><><><><><><><><><><><><><> 336//<><><><><><><><> end screen 9 <><><><><><><><><> 337//<><><><><><><><><><><><><><><><><><><><><><><><> 338 339 340//<><><><><><><><><><><><><><><><><><><><><><><><> 341//<><><><><><><><> begin screen 10 <><><><><><><><> 342//<><><><><><><><><><><><><><><><><><><><><><><><> 343 344 345//<><><><><><><><><><><><><><><><><><><><><><><><> 346//<><><><><><><><> end screen 10 <><><><><><><><><> 347//<><><><><><><><><><><><><><><><><><><><><><><><> 348 349 350//<><><><><><><><><><><><><><><><><><><><><><><><> 351//<><><><><><><><> begin screen 11 <><><><><><><><> 352//<><><><><><><><><><><><><><><><><><><><><><><><> 353 354 355//<><><><><><><><><><><><><><><><><><><><><><><><> 356//<><><><><><><><> end screen 11 <><><><><><><><><> 357//<><><><><><><><><><><><><><><><><><><><><><><><> 358 359 360 361//<><><><><><><><><><><><><><><><><><><><><><><><> 362//<><><><><><><><> begin screen 12 <><><><><><><><> 363//<><><><><><><><><><><><><><><><><><><><><><><><> 364 365 366//<><><><><><><><><><><><><><><><><><><><><><><><> 367//<><><><><><><><> end screen 12 <><><><><><><><><> 368//<><><><><><><><><><><><><><><><><><><><><><><><> 369 370 371 372//**************************************************************************************************** 373//**************************************************************************************************** 374 375 376 377 378 379 380 381//**************************************************************************************************** 382//**************************************************************************************************** 383 384// fin
22102018 graves uno mouth
c_cpp
uno code to sense sound and move mouth
1/* 2last edit monday oct 22 2018 3 4gravesunomouth 5 6graves project 7arduino Uno 8Slave 1 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17 18sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 19 20 analogue pin speaker + 21 \(yellow signal / (red from speaker) 22 \ wire) / 23 \ / 24 *--------[=]-----------*---------[=]----------* 25 | 100k resistor \ 100k resistor | 26 | \ | 27 |(red with white) \ |to arduino ground (black with white) 28to arduino 5v+ speaker - 29 (black from speaker) 30 31*/ 32#include <Servo.h> 33#include <SPI.h> 34 35//---------------------begin declarations----------------------- 36// for servo actions 37Servo mouthServo; 38 39// for gathering and mapping sound data 40int soundPinGraves=A3; // incoming lead from graves dc bias circuit 41int soundPinEcho=A4; // incoming lead from echo dc bias circuit 42int soundDetectedEcho; // stores value from sound pin 43int soundLevelEcho; // converted values that only include 512-1024 44int soundMapEcho; // conversion from 512-1024 to 0-255 45int servoMapEcho; // conversion from 0-255 to 100-70 46int soundDetectedGraves; // stores value from sound pin 47int soundLevelGraves; // converted values that only include 512-1024 48int soundMapGraves; // conversion from 512-1024 to 0-255 49int servoMapGraves; // conversion from 0-255 to 100-70 50 51// communication 52char incomingMouthByte; // for incoming serial data 53char outgoingMouthByte; // for a bit more talkative serial data 54int mouthOnOffNew; // stores mouth state from serial connection 55int mouthOnOffOld; // stores mouth state from serial connection 56int mouthOnOffAdjusted; // value adjusted by 48 for ascii 57 58// for blinking 59const int ledPin = LED_BUILTIN;// the number of the LED pin 60int ledState = LOW; // ledState used to set the LED 61unsigned long previousMillis = 0; // will store last time LED was updated 62//---------------------end declarations----------------------- 63//********************************************************* 64//********************************************************* 65//---------------------begin void setup----------------------- 66//---------------------begin void setup----------------------- 67//---------------------begin void setup----------------------- 68void setup(){ 69 delay(5000); 70 Serial.begin(9600); 71 mouthServo.attach(6); 72 incomingMouthByte = 0; // for incoming serial data 73 outgoingMouthByte = 0; // for a little more talkative serial data 74 mouthOnOffNew = 1; // stores mouth state from serial connection 75 mouthOnOffOld = 1; // stores mouth state from serial connection 76 pinMode(ledPin, OUTPUT); 77 pinMode(soundPinEcho, INPUT); 78 pinMode(soundPinGraves, INPUT); 79} 80//---------------------end void setup----------------------- 81//---------------------end void setup----------------------- 82//---------------------end void setup----------------------- 83//********************************************************** 84//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 85//********************************************************** 86//---------------------begin void loop----------------------- 87//---------------------begin void loop----------------------- 88//---------------------begin void loop----------------------- 89void loop(){ 90 serialDoStuff(); 91 if(mouthOnOffNew == mouthOnOffOld){ 92 if(mouthOnOffNew == 1){ 93 blinkFast(); 94 mouthDoStuffGraves(); 95 mouthDoStuffEcho(); 96 } 97 if(mouthOnOffNew == 2){ 98 blinkSlow(); 99 } 100 } 101 else if(mouthOnOffNew != mouthOnOffOld){ 102 mouthOnOffNew = mouthOnOffOld; 103 } 104} 105//---------------------end void loop----------------------- 106//---------------------end void loop----------------------- 107//---------------------end void loop----------------------- 108//********************************************************* 109//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 110//********************************************************* 111//---------------------begin serialDoStuff ----------------- 112void serialDoStuff(){ 113 if(Serial.available() > 0){ 114 incomingMouthByte = Serial.read(); 115 mouthOnOffAdjusted = incomingMouthByte - '0'; 116 if(mouthOnOffAdjusted == 1){ 117 Serial.flush(); 118 outgoingMouthByte = 1; 119 Serial.write(outgoingMouthByte); 120 mouthOnOffOld = 1; 121 } 122 else if(mouthOnOffAdjusted == 2){ 123 Serial.flush(); 124 outgoingMouthByte = 2; 125 Serial.write(outgoingMouthByte); 126 mouthOnOffOld = 2; 127 } 128/* 129else if(mouthOnOffAdjusted == 3){ 130 Serial.flush(); 131 outgoingMouthByte = 3; 132 Serial.write(outgoingMouthByte); 133 mouthOnOffOld = 3; 134 } 135 else if(mouthOnOffAdjusted == 4){ 136 Serial.flush(); 137 outgoingMouthByte = 4; 138 Serial.write(outgoingMouthByte); 139 mouthOnOffOld = 4; 140 } 141 142 */ 143 } 144} 145//---------------------end serialDoStuff----------------- 146//********************************************************* 147//********************************************************* 148//---------------------begin mouthDoStuffGraves ------------------- 149 150void mouthDoStuffGraves(){ 151 int soundDetectedGraves; // stores value from sound pin 152 int soundLevelGraves; // converted values that only include 512-1024 153 int servoMapGraves; // conversion from 0-255 to 100-70 154 155 156 soundDetectedGraves = analogRead(soundPinGraves); // capture audio signal from dc bias circuit 157 if(soundDetectedGraves<=512){ // runs when negative amplitude detected 158 soundLevelGraves = (512-soundDetectedGraves+512); // takes numbers below 512 and tacks em on top of 512 to create positive amplitudes 159 } 160 else{ 161 soundLevelGraves = soundDetectedGraves; // stores positive amplitudes 162 } 163 164 servoMapGraves = map(soundLevelGraves, 570, 610, 100, 50); // sound map 0-255 is mapped to truncated and inverted servo sweep 100-70 165 if(soundLevelGraves < 700 ){ 166 if(servoMapGraves < 100){ 167 mouthServo.write(servoMapGraves); 168 Serial.print("soundLevelGraves "); 169 Serial.println(soundLevelGraves); 170 Serial.print(" servoMapGraves "); 171 Serial.println(servoMapGraves); 172 Serial.print(" soundDetectedGraves "); 173 Serial.println(soundDetectedGraves); 174 } 175 } 176 else{ 177 mouthServo.write(95); 178 Serial.print("soundLevelGraves "); 179 Serial.println(soundLevelGraves); 180 Serial.print(" servoMapGraves "); 181 Serial.println(servoMapGraves); 182 Serial.print(" soundDetectedGraves "); 183 Serial.println(soundDetectedGraves); 184 } 185 // return soundLevelGraves; 186} 187 188//// ++++++++++++++++++end mouthDoStuffGraves +++++++++++++++++++++++++++++++++ 189//********************************************************* 190//********************************************************* 191//---------------------begin mouthDoStuffEcho ------------------- 192 193void mouthDoStuffEcho(){ 194 int soundDetectedEcho; // stores value from sound pin 195 int soundLevelEcho; // converted values that only include 512-1024 196 int servoMapEcho; // conversion from 0-255 to 100-70 197 198 199 soundDetectedEcho = analogRead(soundPinEcho); // capture audio signal from dc bias circuit 200 if(soundDetectedEcho<=512){ // runs when negative amplitude detected 201 soundLevelEcho = (512-soundDetectedEcho+512); // takes numbers below 512 and tacks em on top of 512 to create positive amplitudes 202 } 203 else{ 204 soundLevelEcho = soundDetectedEcho; // stores positive amplitudes 205 } 206 207 servoMapEcho = map(soundLevelEcho, 570, 610, 100, 50); // sound map 0-255 is mapped to truncated and inverted servo sweep 100-70 208 if(soundLevelEcho < 700 ){ 209 if(servoMapEcho < 100){ 210 mouthServo.write(servoMapEcho); 211 Serial.print("soundLevelEcho "); 212 Serial.println(soundLevelEcho); 213 Serial.print(" servoMapEcho "); 214 Serial.println(servoMapEcho); 215 Serial.print(" soundDetectedEcho "); 216 Serial.println(soundDetectedEcho); 217 } 218 } 219 else{ 220 mouthServo.write(95); 221 Serial.print("soundLevelEcho "); 222 Serial.println(soundLevelEcho); 223 Serial.print(" servoMapEcho "); 224 Serial.println(servoMapEcho); 225 Serial.print(" soundDetectedEcho "); 226 Serial.println(soundDetectedEcho); 227 } 228 // return soundLevelEcho; 229} 230 231//// ++++++++++++++++++end mouthDoStuffEcho +++++++++++++++++++++++++++++++++ 232//********************************************************* 233//********************************************************* 234//---------------------begin blink slow------------------- 235void blinkSlow(){ 236unsigned long currentMillis = millis(); 237const long interval1 = 500; 238 239 if(currentMillis - previousMillis >= interval1) { 240 previousMillis = currentMillis; 241 if(ledState == LOW){ 242 ledState = HIGH; 243 } 244 else{ 245 ledState = LOW; 246 } 247 digitalWrite(ledPin, ledState); 248 } 249} 250//---------------------end blink slow------------------- 251//---------------------begin blink fast ------------------- 252void blinkFast(){ 253unsigned long currentMillis = millis(); 254const long interval2 = 75; 255 if(currentMillis - previousMillis >= interval2){ 256 previousMillis = currentMillis; 257 if(ledState == LOW){ 258 ledState = HIGH; 259 } 260 else{ 261 ledState = LOW; 262 } 263 digitalWrite(ledPin, ledState); 264 } 265} 266//---------------------end blink fast ------------------- 267//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 268//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 269//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 270 271
do you expect me to talk?
c_cpp
No! I expect you to communicate over simple tx/rx ports like you already know how...even though I don't.
1/* 2last edit monday oct 15 2018 midnight 3working on serial coms 4 5 6gravesmegamaster 7 8graves project 9arduino MEGA 2650 10Master 11coded from scratch by wylie jones 12wyliejones@gmail.com 13 14Graves multi arduino build 10/2018 15Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 16two arduino uno's 17slave1 arduino uno to sense sound from graves and echo dot to control mouth 18slave2 arduino uno to control passive sensor array and head servo 19 20sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 21 22 analogue pin speaker + 23 \ / (red from speaker) 24 \ / 25 \ / 26 *--------[=]-----------*---------[=]----------* 27 | resistor \ resistor | 28 | \ | 29 |(red with white) \ |to arduino ground (black with white) 30to arduino 5v+ speaker - 31 (black from speaker) 32 33*/ 34//end notes 35//end notes 36//end notes 37//end notes 38//end notes 39//end notes 40 41 42//********************************************************* 43//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 44//********************************************************* 45 46 47//begin declarations 48//begin declarations 49//begin declarations 50//begin declarations 51//begin declarations 52//begin declarations 53//begin declarations 54 55//#include <TFT.h> 56//#include <Servo.h> 57//#include <stdint.h> 58//#include <SD.h> 59#include <TFTv2.h> 60#include <SPI.h> 61#include <SeeedTouchScreen.h> 62#include <Wire.h> 63 64//const int PIN_SD_CS = 4; // pin of sd card 65 66TouchScreen ts = TouchScreen(XP, YP, XM, YM); 67int zMax; // maximum pressure to detect 68int zMin; // minimum pressure to detect 69 70int buttonPressed; // stores which button was pressed 71unsigned long newButtonTime; // debounce 72unsigned long oldButtonTime; // debounce 73unsigned long buttonTimeDifference; // debounce 74unsigned long debounceTime; // debounce 75int buttonGroup; // sets kinds of buttons on screen 76 77int currentScreen; // identifies current screen by adding x y and z 78int x; // for ones 79int y; // for tens 80int z; // for hundreds 81 82unsigned long backlightTimer; // for backlight timeout 83int backLightState; // status of backlight 1 for on and 0 for off 84unsigned long backlightTimeDifference; 85unsigned long newBacklightTime; 86unsigned long oldBacklightTime; 87 88int incomingMouthByte; 89int outgoingMouthByte; 90int mouthOnOff; 91 92int incomingHeadByte; 93int outgoingHeadByte; 94int headOnOff; 95 96//end declarations 97//end declarations 98//end declarations 99//end declarations 100//end declarations 101//end declarations 102//end declarations 103//end declarations 104//end declarations 105 106//********************************************************* 107//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 108//********************************************************* 109 110// begin void setup 111// begin void setup 112// begin void setup 113// begin void setup 114// begin void setup 115// begin void setup 116// begin void setup 117// begin void setup 118// begin void setup 119// begin void setup 120// begin void setup 121void setup() { 122Serial.begin(9600); 123 oldButtonTime = millis(); 124 newButtonTime = millis(); 125 Tft.TFTinit(); // init TFT library 126 TFT_BL_ON; // turn on the background light 127 backLightState = 1; 128 x = 0; 129 y = 0; 130 z = 0; 131 buttonPressed = 4; 132 buttonGroup = 0; 133 incomingHeadByte = 0; 134 incomingMouthByte = 0; 135 136 //////////////////////////////// 137 //// manually set variables //// 138 //////////////////////////////// 139 140 debounceTime = 1000; // button debounce in milliseconds 141 zMax = 460; // maximum pressure to detect 142 zMin = 100; // minimum pressure to detect 143 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 144 145 146 currentScreen = 0; 147 callScreen(); 148 149} //void setup() 150// end void setup 151// end void setup 152// end void setup 153// end void setup 154// end void setup 155// end void setup 156// end void setup 157// end void setup 158 159//********************************************************* 160//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 161//********************************************************* 162 163// begin void loop 164// begin void loop 165// begin void loop 166// begin void loop 167// begin void loop 168// begin void loop 169// begin void loop 170// begin void loop 171// begin void loop 172// begin void loop 173// begin void loop 174// begin void loop 175// begin void loop 176// begin void loop 177 178void loop() { 179 180 tftBacklightTimeout(); // check time and turn off backlight 181 182 if(buttonGroup == 0){ // most regular pages 183 tftButtonGroup0(); // gather information from touch screen touches 184 buttonTimeDifference = newButtonTime - oldButtonTime; 185 if(debounceTime < buttonTimeDifference){ 186 whatScreen(); 187 callScreen(); 188 oldButtonTime = newButtonTime; 189 showStuff(); // serial prints 190 tftDisplay(); // display x y coordinates on tft display 191 } 192 } 193 if(buttonGroup == 1){ // on off buttons 194 tftButtonGroup1(); // gather information from touch screen touches 195 buttonTimeDifference = newButtonTime - oldButtonTime; 196 if(debounceTime < buttonTimeDifference){ 197 whatScreen(); 198 callScreen(); 199 oldButtonTime = newButtonTime; 200 showStuff(); // serial prints 201 tftDisplay(); // display x y coordinates on tft display 202 mouthUnoTxRx(); 203 } 204 } 205 if(buttonGroup == 2){ // head buttons 206 tftButtonGroup2(); // gather information from touch screen touches 207 buttonTimeDifference = newButtonTime - oldButtonTime; 208 if(debounceTime < buttonTimeDifference){ 209 whatScreen(); 210 callScreen(); 211 oldButtonTime = newButtonTime; 212 showStuff(); // serial prints 213 tftDisplay(); // display x y coordinates on tft display 214 } 215 } 216 217 218} //void loop() 219 220// end of void loop 221// end of void loop 222// end of void loop 223// end of void loop 224// end of void loop 225// end of void loop 226// end of void loop 227// end of void loop 228// end of void loop 229// end of void loop 230// end of void loop 231// end of void loop 232// end of void loop 233// end of void loop 234// end of void loop 235 236//**************************************************************************************************** 237//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 238//**************************************************************************************************** 239///////////////////////////////////////////////////////////////////////////////////////////////////////// 240///////////////////////////////////////// functions /////////////////////////////////////////////////// 241///////////////////////////////////////////////////////////////////////////////////////////////////////// 242//**************************************************************************************************** 243//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 244//**************************************************************************************************** 245 246//--------------------------begin tftBacklightTimeout---------------------------------- 247void tftBacklightTimeout(){ 248 newBacklightTime = millis(); 249 if(backLightState = 0){ 250 backlightTimeDifference = newBacklightTime - oldBacklightTime; 251 if(backlightTimer > backlightTimeDifference){ 252 backlightTimeDifference = newBacklightTime - oldBacklightTime; 253 TFT_BL_ON; // turn on the background light 254 backLightState = 1; 255 oldBacklightTime = millis(); 256 } 257 } 258 if(backLightState = 1){ 259 backlightTimeDifference = newBacklightTime - oldBacklightTime; 260 if(backlightTimer < backlightTimeDifference){ 261 backlightTimeDifference = newBacklightTime - oldBacklightTime; 262 TFT_BL_OFF; // turn off the background light 263 backLightState = 0; 264 oldBacklightTime = millis(); 265 } 266 } 267} 268//--------------------------end tftBacklightTimeout---------------------------------- 269 270//**************************************************************************************************** 271//**************************************************************************************************** 272 273//--------------------------begin tftButtonGroup0---------------------------------- 274//--------------------------begin tftButtonGroup0---------------------------------- 275//--------------------------begin tftButtonGroup0---------------------------------- 276//--------------------------begin tftButtonGroup0---------------------------------- 277int tftButtonGroup0(){ 278 Point p = ts.getPoint(); 279 if(zMin<p.z && p.z<zMax){ 280 TFT_BL_ON; // turn on the background light 281 backLightState = 1; 282 oldBacklightTime = millis(); 283 newButtonTime = millis(); 284 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 285 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 286//Button 1 287 if(75<p.x && p.x<140){ 288 if(100<p.y && p.y<164){ 289 buttonPressed = 1; 290 } 291//Button 2 292 if(164<p.y && p.y<240){ 293 buttonPressed = 2; 294 } 295//Button 3 296 if(240<p.y && p.y<310){ 297 buttonPressed = 3; 298 } 299 } 300 } 301//Button 4 302 if(10<p.x && p.x<75){ 303 if(100<p.y && p.y<240){ 304 buttonPressed = 4; 305 } 306 } 307}//void tftButtonGroup0 308//--------------------------end tftButtonGroup0 code---------------------------------- 309//--------------------------end tftButtonGroup0 code---------------------------------- 310//--------------------------end tftButtonGroup0 code---------------------------------- 311//--------------------------end tftButtonGroup0 code---------------------------------- 312//--------------------------end tftButtonGroup0 code---------------------------------- 313//**************************************************************************************************** 314//**************************************************************************************************** 315 316//--------------------------begin tftButtonGroup1---------------------------------- 317//--------------------------begin tftButtonGroup1---------------------------------- 318//--------------------------begin tftButtonGroup1---------------------------------- 319//--------------------------begin tftButtonGroup1---------------------------------- 320int tftButtonGroup1(){ // for mouth 321buttonPressed = 0; 322 Point p = ts.getPoint(); 323 if(zMin<p.z && p.z<zMax){ 324 TFT_BL_ON; // turn on the background light 325 backLightState = 1; 326 oldBacklightTime = millis(); 327 newButtonTime = millis(); 328 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 329 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 330//Button 1 331 if(75<p.x && p.x<140){ 332 if(100<p.y && p.y<164){ 333 mouthOnOff = 1; // on 334 Serial.print("mouthOnOff set to "); 335 Serial.println(mouthOnOff); 336 } 337//Button 2 338 if(164<p.y && p.y<240){ 339 mouthOnOff = 0; // off 340 Serial.print("mouthOnOff set to "); 341 Serial.println(mouthOnOff); 342 } 343//Button 3 344// if(240<p.y && p.y<310){ 345// buttonPressed = 3; 346// } 347 } 348 } 349//Button 4 350 if(10<p.x && p.x<75){ 351 if(100<p.y && p.y<240){ 352 buttonPressed = 4; 353 buttonGroup = 0; 354 } 355 } 356}//void tftButtonGroup1 357//--------------------------end tftButtonGroup1 code---------------------------------- 358//--------------------------end tftButtonGroup1 code---------------------------------- 359//--------------------------end tftButtonGroup1 code---------------------------------- 360//--------------------------end tftButtonGroup1 code---------------------------------- 361//--------------------------end tftButtonGroup1 code---------------------------------- 362//**************************************************************************************************** 363//**************************************************************************************************** 364 365//--------------------------begin tftButtonGroup2---------------------------------- 366//--------------------------begin tftButtonGroup2---------------------------------- 367//--------------------------begin tftButtonGroup2---------------------------------- 368//--------------------------begin tftButtonGroup2---------------------------------- 369int tftButtonGroup2(){ // for head 370buttonPressed = 0; 371 Point p = ts.getPoint(); 372 if(zMin<p.z && p.z<zMax){ 373 TFT_BL_ON; // turn on the background light 374 backLightState = 1; 375 oldBacklightTime = millis(); 376 newButtonTime = millis(); 377 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 378 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 379//Button 1 380 if(75<p.x && p.x<140){ 381 if(100<p.y && p.y<164){ 382 headOnOff = 1; // on 383 } 384//Button 2 385 if(164<p.y && p.y<240){ 386 headOnOff = 0; // off 387 } 388//Button 3 389// if(240<p.y && p.y<310){ 390// buttonPressed = 3; 391// } 392 } 393 } 394//Button 4 395 if(10<p.x && p.x<75){ 396 if(100<p.y && p.y<240){ 397 buttonPressed = 4; 398 buttonGroup = 0; 399 } 400 } 401}//void tftButtonGroup2 402//--------------------------end tftButtonGroup2 code---------------------------------- 403//--------------------------end tftButtonGroup2 code---------------------------------- 404//--------------------------end tftButtonGroup2 code---------------------------------- 405//--------------------------end tftButtonGroup2 code---------------------------------- 406//--------------------------end tftButtonGroup2 code---------------------------------- 407//**************************************************************************************************** 408//**************************************************************************************************** 409//-------------------------- begin whatScreen function ------------------------- 410//-------------------------- begin whatScreen function ------------------------- 411//-------------------------- begin whatScreen function ------------------------- 412//-------------------------- begin whatScreen function ------------------------- 413 414int whatScreen(){ 415 if(x == 0){ 416 if(buttonPressed == 1){ 417 x = x + 1; 418 Serial.println("x + 1"); 419 } 420 if(buttonPressed == 2){ 421 x = x + 2; 422 Serial.println("x + 2"); 423 } 424 if(buttonPressed == 3){ 425 x = x + 3; 426 Serial.println("x + 3"); 427 } 428 if(buttonPressed == 4){ 429 x = 0; 430 Serial.println("x = 0"); 431 } 432 if(buttonPressed == 5){ 433 x = 0; 434 y = 0; 435 z = 0; 436 Serial.println("xyz all 0"); 437 } 438 } 439 else if(x >> 0){ 440 if(y == 0){ 441 if(buttonPressed == 1){ 442 y = y + 10; 443 Serial.println("y + 10"); 444 } 445 if(buttonPressed == 2){ 446 y = y + 20; 447 Serial.println("y + 20"); 448 } 449 if(buttonPressed == 3){ 450 y = y + 30; 451 Serial.println("y + 30"); 452 } 453 if(buttonPressed == 4){ 454 x = 0; 455 Serial.println("x = 0"); 456 } 457 if(buttonPressed == 5){ 458 x = 0; 459 y = 0; 460 z = 0; 461 Serial.println("xyz all 0"); 462 } 463 } 464 else if (y >> 0){ 465 if(buttonPressed == 1){ 466 z = z + 100; 467 Serial.println("z + 100"); 468 } 469 if(buttonPressed == 2){ 470 z = z + 200; 471 Serial.println("z + 200"); 472 } 473 if(buttonPressed == 3){ 474 z = z + 300; 475 Serial.println("z + 300"); 476 } 477 if(buttonPressed == 4){ 478 if(z == 0){ 479 y = 0; 480 Serial.println("y = 0"); 481 } 482 else if(z >> 0){ 483 z = 0; 484 Serial.println("z = 0"); 485 } 486 } 487 if(buttonPressed == 5){ 488 x = 0; 489 y = 0; 490 z = 0; 491 Serial.println("xyz all 0"); 492 } 493 }//y>0 494 }//x>0 495 currentScreen = z+y+x; 496 if(currentScreen == 122){ 497 buttonGroup=1; 498 } 499 if(currentScreen == 222){ 500 buttonGroup=1; 501 } 502 if(currentScreen == 23){ 503 buttonGroup=2; 504 } 505} 506//-------------------------- end whatScreen function ------------------------- 507//-------------------------- end whatScreen function ------------------------- 508//-------------------------- end whatScreen function ------------------------- 509//-------------------------- end whatScreen function ------------------------- 510//-------------------------- end whatScreen function ------------------------- 511 512//**************************************************************************************************** 513//**************************************************************************************************** 514 515//--------------------------begin mouthUnoTxRx---------------------------------- 516 517void mouthUnoTxRx(){ 518 outgoingMouthByte = mouthOnOff; 519 if(Serial1){ 520 Serial1.println(outgoingMouthByte); // send to serial connection 521// incomingMouthByte = Serial1.read(); // read the incoming byte: 522 Serial.print("uno mouth wrote: "); 523 Serial.println(outgoingMouthByte); 524 } 525} 526 527//--------------------------end mouthUnoTxRx -------------------------------------- 528//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 529//--------------------------begin headUnoTxRx -------------------------------------- 530 531// call slave1 arduino for data 532 533void headUnoTxRx(){ 534 outgoingHeadByte = headOnOff; 535 if(Serial2){ 536 Serial2.println(outgoingHeadByte); // send to serial connection 537 incomingHeadByte = Serial2.read(); // read the incoming byte: 538 Serial.print("uno head received and wrote: "); 539 Serial.println(incomingHeadByte, DEC); 540 } 541} 542 543// call slave2 arduino for data 544//--------------------------end headUnoTxRx -------------------------------------- 545 546//**************************************************************************************************** 547//**************************************************************************************************** 548 549//--------------------------begin tftDisplay code---------------------------------- 550void tftDisplay(){ 551 Point p = ts.getPoint(); 552 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 553 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 554 Tft.fillRectangle(0, 225, 60, 30, BLACK); 555 Tft.drawNumber((p.x), 0, 225, 3, GREEN); 556 Tft.fillRectangle(180, 225, 60, 30, BLACK); 557 Tft.drawNumber((p.y), 180, 225, 3, GREEN); 558 Tft.fillRectangle(100, 225, 60, 30, BLACK); 559 Tft.drawNumber((buttonPressed), 100, 225, 3, GREEN); 560 Tft.fillRectangle(70, 160, 60, 30, BLACK); 561 Tft.drawNumber((mouthOnOff), 70, 160, 3, GREEN); 562 Tft.fillRectangle(140, 160, 60, 30, BLACK); 563 Tft.drawNumber((headOnOff), 140, 160, 3, GREEN); 564 Tft.fillRectangle(120, 290, 60, 30, BLACK); 565 Tft.drawNumber((currentScreen), 120, 290, 3, GREEN); 566 567 568}// void tftDisplay 569//--------------------------end tftDisplay code------------------------------------ 570 571//**************************************************************************************************** 572//**************************************************************************************************** 573 574//-------------------------- begin mouth on off function -------------------------- 575//-------------------------- end mouth on off function -------------------------- 576 577//**************************************************************************************************** 578//**************************************************************************************************** 579 580//-------------------------- begin head on off function -------------------------- 581//-------------------------- end head on off function ------------------------- 582 583//**************************************************************************************************** 584//**************************************************************************************************** 585 586//-------------------------- begin serial display function -------------------------- 587void showStuff(){ 588 Serial.println("------/ last update /-------"); 589// Serial.println("------begin display-------"); 590 Serial.print("buttonPressed "); 591 Serial.println(buttonPressed); 592 Serial.print("x "); 593 Serial.println(x); 594 Serial.print("y "); 595 Serial.println(y); 596 Serial.print("z "); 597 Serial.println(z); 598 Serial.print("currentScreen "); 599 Serial.println(currentScreen); 600// Serial.println("-------end display--------"); 601 Serial.println(""); 602 Serial.println(""); 603 Serial.println(""); 604 } 605//-------------------------- end serial display function ------------------------- 606 607 608//**************************************************************************************************** 609//**************************************************************************************************** 610 611//--------------------------- Primary screen maps -------------------------------- 612/* 613******** 614updates needed 615******** 6161 ditch the contrast 6172 ditch the brightness 6183 setup screen timeout 619 620 621 622 623screen 0000 A)Home 624 screen 0001 a)settings 625 screen 0011 -brightness 626 screen 0011 -contrast 627 screen 0011 -screen lock time out 628 screen 0001 b)sensor monitors 629 screen 0021 -pir 630 screen 0121 *report pir detection 631 screen 0021 -sound 632 screen 0221 *sense alexa sound 633 screen 0221 *sense graves sound 634 screen 0221 *report mouth servo position 635 screen 0221 *adjust sensitivity? 636 screen 0021 -head potentiometer 637 screen 0021 -bluetooth 638 screen 0001 c)bluetooth 639 screen 0031 -on 640 screen 0031 -off 641 screen 0031 -monitor 642screen 0000 B)Mouth Control 643 screen 0002 a)test button 644 screen 0012 -open 645 screen 0012 -close 646 screen 0012 -push button chicken switch 647 screen 0002 b)sound sensors on/off 648 screen 0022 -alexa sense 649 screen 0122 *on 650 screen 0122 *off 651 screen 0122 *monitor sensor 652 screen 0022 -graves sense 653 screen 0222 *on 654 screen 0222 *off 655 screen 0222 *monitor sensors 656 screen 0002 c)sound sensor status 657 screen 0032 -alexa 658 screen 0032 -graves 659screen 0000 C)Head Control 660 screen 0003 a)pir on/off 661 screen 0013 -on 662 screen 0013 -off 663 screen 0013 -sensor 664 screen 0003 b)manual point 665 screen 0023 -slider 666*/ 667//**************************************************************************************************** 668//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 669//**************************************************************************************************** 670//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 671//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 672//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 673//**************************************************************************************************** 674//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 675//**************************************************************************************************** 676 677//-------------------------- begin callScreen function ------------------------- 678//-------------------------- begin callScreen function ------------------------- 679//-------------------------- begin callScreen function ------------------------- 680//-------------------------- begin callScreen function ------------------------- 681//-------------------------- begin callScreen function ------------------------- 682//-------------------------- begin callScreen function ------------------------- 683//-------------------------- begin callScreen function ------------------------- 684//-------------------------- begin callScreen function ------------------------- 685//-------------------------- begin callScreen function ------------------------- 686//-------------------------- begin callScreen function ------------------------- 687//-------------------------- begin callScreen function ------------------------- 688 689int callScreen(){ 690 Tft.fillRectangle(0, 0, 240, 320, BLACK); 691 692//<><><><><><><><><><><><><><><><><><><><><><><><> 693//<><><><><><><><> begin screen 0000 master <><><><><><><><> 694//<><><><><><><><><><><><><><><><><><><><><><><><> 695if(currentScreen == 0){ 696 // " " 697 Tft.drawString("GRAVES",0,5,4, GREEN); 698 Tft.drawString("INTERFACE",10,50,4,GREEN); 699 Tft.drawString("Home", 80,130, 3, GREEN); 700 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 701 Tft.drawString("Head Control", 10, 260, 3, GREEN); 702} 703//<><><><><><><><><><><><><><><><><><><><><><><><> 704//<><><><><><><><> end screen 0000 master <><><><><><><><><> 705//<><><><><><><><><><><><><><><><><><><><><><><><> 706 707//<><><><><><><><><><><><><><><><><><><><><><><><> 708//<><><><><><><><> begin screen 0001 <><><><><><><><> 709//<><><><><><><><><><><><><><><><><><><><><><><><> 710 if(currentScreen == 1){ 711 // " " 712 Tft.drawString("MEGA 2560",00,5,4,BLUE); 713 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 714 Tft.drawString("Settings", 10,130, 3, BLUE); 715 Tft.drawString("Sensors", 20, 195, 3, BLUE); 716 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 717 Tft.drawString("<", 0, 160, 3, GREEN); // back button 718} 719//<><><><><><><><><><><><><><><><><><><><><><><><> 720//<><><><><><><><> end screen 0001 <><><><><><><><><> 721//<><><><><><><><><><><><><><><><><><><><><><><><> 722 723//<><><><><><><><><><><><><><><><><><><><><><><><> 724//<><><><><><><><> begin screen 0011 <><><><><><><><> 725//<><><><><><><><><><><><><><><><><><><><><><><><> 726 if(currentScreen == 11){ 727 // " " 728 Tft.drawString("MEGA 2560",00,5,4,BLUE); 729 Tft.drawString("SETTINGS",10,50,4,YELLOW); 730 Tft.drawString("Brightness", 80,130, 3, BLUE); 731 Tft.drawString("Contrast", 05, 195, 3, GREEN); 732 Tft.drawString("Timeout", 10, 260, 3, GREEN); 733 Tft.drawString("<", 0, 160, 3, GREEN); // back button 734} 735 736//<><><><><><><><><><><><><><><><><><><><><><><><> 737//<><><><><><><><> end screen 0011 <><><><><><><><><> 738//<><><><><><><><><><><><><><><><><><><><><><><><> 739 740//<><><><><><><><><><><><><><><><><><><><><><><><> 741//<><><><><><><><> begin screen 0021 <><><><><><><><> 742//<><><><><><><><><><><><><><><><><><><><><><><><> 743 if(currentScreen == 21){ 744 // " " 745 Tft.drawString("MEGA 2560",00,5,4,BLUE); 746 Tft.drawString("SENSORS",10,50,4,YELLOW); 747 Tft.drawString("PIR Array", 80,130, 3, BLUE); 748 Tft.drawString("Sound", 05, 195, 3, GREEN); 749 Tft.drawString("Head Position", 10, 260, 3, GREEN); 750 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 751 Tft.drawString("<", 0, 160, 3, GREEN); // back button 752} 753//<><><><><><><><><><><><><><><><><><><><><><><><> 754//<><><><><><><><> end screen 0021 <><><><><><><><><> 755//<><><><><><><><><><><><><><><><><><><><><><><><> 756 757//<><><><><><><><><><><><><><><><><><><><><><><><> 758//<><><><><><><><> begin screen 0121 <><><><><><><><> 759//<><><><><><><><><><><><><><><><><><><><><><><><> 760 if(currentScreen == 121){ 761 // " " 762 Tft.drawString("PIR",0,5,4,BLUE); 763 Tft.drawString("ARRAY",10,50,4,YELLOW); 764 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 765 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 766 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 767 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 768 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 769 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 770 Tft.drawString("<", 0, 160, 3, GREEN); // back button 771} 772//<><><><><><><><><><><><><><><><><><><><><><><><> 773//<><><><><><><><> end screen 0121 <><><><><><><><><> 774//<><><><><><><><><><><><><><><><><><><><><><><><> 775 776//<><><><><><><><><><><><><><><><><><><><><><><><> 777//<><><><><><><><> begin screen 0221 <><><><><><><><> 778//<><><><><><><><><><><><><><><><><><><><><><><><> 779 if(currentScreen == 221){ 780 // " " 781 Tft.drawString("SOUND",0,5,4,BLUE); 782 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 783 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 784 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 785 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 786 Tft.drawString("<", 0, 160, 3, GREEN); // back button 787} 788//<><><><><><><><><><><><><><><><><><><><><><><><> 789//<><><><><><><><> end screen 0221 <><><><><><><><><> 790//<><><><><><><><><><><><><><><><><><><><><><><><> 791 792//<><><><><><><><><><><><><><><><><><><><><><><><> 793//<><><><><><><><> begin screen 0031 <><><><><><><><> 794//<><><><><><><><><><><><><><><><><><><><><><><><> 795 if(currentScreen == 31){ 796 // " " 797 Tft.drawString("Bluetooth",0,5,4,BLUE); 798 Tft.drawString("Control",10,50,4,YELLOW); 799 Tft.drawString("On", 80,130, 3, BLUE); 800 Tft.drawString("Off", 05, 195, 3, GREEN); 801 Tft.drawString("Monitor", 10, 260, 3, GREEN); 802 Tft.drawString("<", 0, 160, 3, GREEN); // back button 803} 804//<><><><><><><><><><><><><><><><><><><><><><><><> 805//<><><><><><><><> end screen 0031 <><><><><><><><><> 806//<><><><><><><><><><><><><><><><><><><><><><><><> 807 808//<><><><><><><><><><><><><><><><><><><><><><><><> 809//<><><><><><><><> begin screen 0002 <><><><><><><><> 810//<><><><><><><><><><><><><><><><><><><><><><><><> 811 if(currentScreen == 2){ 812 // " " 813 Tft.drawString("Mouth",0,5,4,BLUE); 814 Tft.drawString("Control",10,50,4,YELLOW); 815 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 816 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 817 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 818 Tft.drawString("<", 0, 160, 3, GREEN); // back button 819 } 820//<><><><><><><><><><><><><><><><><><><><><><><><> 821//<><><><><><><><> end screen 0002 <><><><><><><><><> 822//<><><><><><><><><><><><><><><><><><><><><><><><> 823 824 825//<><><><><><><><><><><><><><><><><><><><><><><><> 826//<><><><><><><><> begin screen 0012 <><><><><><><><> 827//<><><><><><><><><><><><><><><><><><><><><><><><> 828 if(currentScreen == 12){ 829 // " " 830 Tft.drawString("Jaw Test",0,5,4,BLUE); 831 Tft.drawString("Operations",10,50,4,YELLOW); 832 Tft.drawString("Open", 80,130, 3, BLUE); 833 Tft.drawString("Close", 05, 195, 3, GREEN); 834 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 835 Tft.drawString("<", 0, 160, 3, GREEN); // back button 836} 837//<><><><><><><><><><><><><><><><><><><><><><><><> 838//<><><><><><><><> end screen 0012 <><><><><><><><><> 839//<><><><><><><><><><><><><><><><><><><><><><><><> 840 841 842//<><><><><><><><><><><><><><><><><><><><><><><><> 843//<><><><><><><><> begin screen 0022 <><><><><><><><> 844//<><><><><><><><><><><><><><><><><><><><><><><><> 845 if(currentScreen == 22){ 846 // " " 847 Tft.drawString("Sound",0,5,4,BLUE); 848 Tft.drawString("Sensors",10,50,4,YELLOW); 849 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 850 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 851 Tft.drawString("Monitor", 10, 260, 3, GREEN); 852 Tft.drawString("<", 0, 160, 3, GREEN); // back button 853} 854//<><><><><><><><><><><><><><><><><><><><><><><><> 855//<><><><><><><><> end screen 0022 <><><><><><><><><> 856//<><><><><><><><><><><><><><><><><><><><><><><><> 857 858 859 860//<><><><><><><><><><><><><><><><><><><><><><><><> 861//<><><><><><><><> begin screen 0122 <><><><><><><><> 862//<><><><><><><><><><><><><><><><><><><><><><><><> 863 if(currentScreen == 122){ 864 // " " 865 Tft.drawString("Alexa Sense",0,5,4,BLUE); 866 Tft.drawString("Operations",10,50,4,YELLOW); 867 Tft.drawString("On", 120, 130, 3, GREEN); 868 Tft.drawString("Off", 115, 195, 3, RED); 869 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 870 Tft.drawString("<", 0, 160, 3, GREEN); // back button 871} 872//<><><><><><><><><><><><><><><><><><><><><><><><> 873//<><><><><><><><> end screen 0122 <><><><><><><><><> 874//<><><><><><><><><><><><><><><><><><><><><><><><> 875 876//<><><><><><><><><><><><><><><><><><><><><><><><> 877//<><><><><><><><> begin screen 0222 <><><><><><><><> 878//<><><><><><><><><><><><><><><><><><><><><><><><> 879 if(currentScreen == 222){ 880 // " " 881 Tft.drawString("Graves Sense",0,5,4,BLUE); 882 Tft.drawString("Operations",10,50,4,YELLOW); 883 Tft.drawString("On", 120, 130, 3, GREEN); 884 Tft.drawString("Off", 115, 195, 3, RED); 885 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 886 Tft.drawString("<", 0, 160, 3, GREEN); // back button 887} 888//<><><><><><><><><><><><><><><><><><><><><><><><> 889//<><><><><><><><> end screen 0222 <><><><><><><><><> 890//<><><><><><><><><><><><><><><><><><><><><><><><> 891 892//<><><><><><><><><><><><><><><><><><><><><><><><> 893//<><><><><><><><> begin screen 0032 <><><><><><><><> 894//<><><><><><><><><><><><><><><><><><><><><><><><> 895 if(currentScreen == 32){ 896 // " " 897 Tft.drawString("Sound Sense",0,5,4,BLUE); 898 Tft.drawString("Monitors",10,50,4,YELLOW); 899 Tft.drawString("Alexa", 80,130, 3, BLUE); 900 Tft.drawString("Graves", 05, 195, 3, GREEN); 901 Tft.drawString("<", 0, 160, 3, GREEN); // back button 902} 903//<><><><><><><><><><><><><><><><><><><><><><><><> 904//<><><><><><><><> end screen 0032 <><><><><><><><><> 905//<><><><><><><><><><><><><><><><><><><><><><><><> 906 907//<><><><><><><><><><><><><><><><><><><><><><><><> 908//<><><><><><><><> begin screen 0003 <><><><><><><><> 909//<><><><><><><><><><><><><><><><><><><><><><><><> 910 if(currentScreen == 3){ 911 // " " 912 Tft.drawString("Head Control",0,5,4,BLUE); 913 Tft.drawString("Operations",10,50,4,YELLOW); 914 Tft.drawString("PIR Array", 80,130, 3, BLUE); 915 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 916 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 917 Tft.drawString("<", 0, 160, 3, GREEN); // back button 918} 919//<><><><><><><><><><><><><><><><><><><><><><><><> 920//<><><><><><><><> end screen 0003 <><><><><><><><><> 921//<><><><><><><><><><><><><><><><><><><><><><><><> 922 923//<><><><><><><><><><><><><><><><><><><><><><><><> 924//<><><><><><><><> begin screen 0013 <><><><><><><><> 925//<><><><><><><><><><><><><><><><><><><><><><><><> 926 if(currentScreen == 13){ 927 // " " 928 Tft.drawString("PIR Control",0,5,4,BLUE); 929 Tft.drawString("Operations",10,50,4,YELLOW); 930 Tft.drawString("On", 80,130, 3, BLUE); 931 Tft.drawString("Off", 05, 195, 3, GREEN); 932 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 933 Tft.drawString("<", 0, 160, 3, GREEN); // back button 934} 935//<><><><><><><><><><><><><><><><><><><><><><><><> 936//<><><><><><><><> end screen 0013 <><><><><><><><><> 937//<><><><><><><><><><><><><><><><><><><><><><><><> 938 939//<><><><><><><><><><><><><><><><><><><><><><><><> 940//<><><><><><><><> begin screen 0023 <><><><><><><><> 941//<><><><><><><><><><><><><><><><><><><><><><><><> 942 if(currentScreen == 23){ 943 // " " 944 Tft.drawString("Graves Head",0,5,3,BLUE); 945 Tft.drawString("Operations",10,50,3,YELLOW); 946 Tft.drawString("On", 120, 130, 3, GREEN); 947 Tft.drawString("Off", 115, 195, 3, RED); 948// Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 949 Tft.drawString("<", 0, 160, 3, GREEN); // back button 950} 951//<><><><><><><><><><><><><><><><><><><><><><><><> 952//<><><><><><><><> end screen 0023 <><><><><><><><><> 953//<><><><><><><><><><><><><><><><><><><><><><><><> 954 955 956//<><><><><><><><><><><><><><><><><><><><><><><><> 957//<><><><><><><><> begin screen 0422 <><><><><><><><> 958//<><><><><><><><><><><><><><><><><><><><><><><><> 959 if(currentScreen == 422){ 960 // " " 961 Tft.drawString("Command Sent",0,5,3,BLUE); 962 Tft.drawString("Press Back to",0,55,3,YELLOW); 963 Tft.drawString("Contiue", 50,105, 3, BLUE); 964 Tft.drawString("<", 0, 160, 3, GREEN); // back button 965} 966//<><><><><><><><><><><><><><><><><><><><><><><><> 967//<><><><><><><><> end screen 0422 <><><><><><><><><> 968//<><><><><><><><><><><><><><><><><><><><><><><><> 969 970 971////<><><><><><><><><><><><><><><><><><><><><><><><> 972////<><><><><><><><> begin screen lost <><><><><><><><> 973////<><><><><><><><><><><><><><><><><><><><><><><><> 974// else if(currentScreen){ 975// // " " 976// Tft.drawString("Screen not",0,5,3,BLUE); 977// Tft.drawString("found. Please",40,50,3,YELLOW); 978// Tft.drawString("use the back", 80,130, 3, BLUE); 979// Tft.drawString("button to", 05, 195, 3, GREEN); 980// Tft.drawString("return to fun", 10, 260, 3, GREEN); 981// Tft.drawString("<", 0, 160, 3, GREEN); // back button 982//} 983////<><><><><><><><><><><><><><><><><><><><><><><><> 984////<><><><><><><><> end screen lost <><><><><><><><><> 985////<><><><><><><><><><><><><><><><><><><><><><><><> 986 987}// callScreen 988//-------------------------- end callScreen function ------------------------- 989//-------------------------- end callScreen function ------------------------- 990//-------------------------- end callScreen function ------------------------- 991//-------------------------- end callScreen function ------------------------- 992//-------------------------- end callScreen function ------------------------- 993//-------------------------- end callScreen function ------------------------- 994//-------------------------- end callScreen function ------------------------- 995//-------------------------- end callScreen function ------------------------- 996//-------------------------- end callScreen function ------------------------- 997//-------------------------- end callScreen function ------------------------- 998//-------------------------- end callScreen function ------------------------- 999//-------------------------- end callScreen function ------------------------- 1000//-------------------------- end callScreen function ------------------------- 1001 1002 1003//**************************************************************************************************** 1004//**************************************************************************************************** 1005 1006 1007 1008 1009 1010 1011 1012//**************************************************************************************************** 1013//**************************************************************************************************** 1014 1015// fin
22102018 graves mega master
c_cpp
code for arduino 2560 contols tft along with sending on off commands to head uno and mouth uno
1/* 2last edit monday oct 22 2018 3 4gravesmegamaster 5 6graves 7 project 8arduino MEGA 2650 9Master 10coded from scratch by wylie jones 11wyliejones@gmail.com 12 13Graves 14 multi arduino build 10/2018 15Arduino mega 2560 with 240/320 tft and micro sd card 16 (for storing screen backgrounds) 17two arduino uno's 18slave1 arduino uno to sense 19 sound from graves and echo dot to control mouth 20slave2 arduino uno to control 21 passive sensor array and head servo 22 23sound is sensed with a simple DC bias 24 circuit to capture line level input to be used as a digital signal 25 26 analogue 27 pin speaker + 28 \(yellow signal / 29 (red from speaker) 30 \ wire) / 31 \\ 32 / 33 *--------[=]-----------*---------[=]----------* 34 35 | resistor \ resistor | 36 | \\ 37 | 38 |(red with white) \ |to arduino 39 ground (black with white) 40to arduino 5v+ speaker - 41 (black 42 from speaker) 43 44*/ 45//end notes 46//end notes 47//end notes 48//end notes 49//end 50 notes 51//end notes 52 53 54//********************************************************* 55//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 56//********************************************************* 57 58 59//begin 60 declarations 61//begin declarations 62//begin declarations 63//begin declarations 64//begin 65 declarations 66//begin declarations 67//begin declarations 68 69//#include <TFT.h> 70//#include 71 <Servo.h> 72//#include <stdint.h> 73//#include <SD.h> 74#include <TFTv2.h> 75#include 76 <SPI.h> 77#include <SeeedTouchScreen.h> 78//#include <Wire.h> 79 80//const 81 int PIN_SD_CS = 4; // pin of sd card 82 83TouchScreen ts 84 = TouchScreen(XP, YP, XM, YM); 85int zMax; // maximum pressure to detect 86int 87 zMin; // minimum pressure to detect 88 89int buttonPressed; // stores which button 90 was pressed 91unsigned long newButtonTime; // debounce 92unsigned long oldButtonTime; 93 // debounce 94unsigned long buttonTimeDifference; // debounce 95unsigned long 96 debounceTime; // debounce 97int buttonGroup; // sets kinds of buttons on screen 98 99int 100 currentScreen; // identifies current screen by adding x y and z 101int x; // for 102 ones 103int y; // for tens 104int z; // for hundreds 105 106unsigned long backlightTimer; 107 // for backlight timeout 108int backLightState; // status of backlight 1 for on 109 and 0 for off 110unsigned long backlightTimeDifference; 111unsigned long newBacklightTime; 112unsigned 113 long oldBacklightTime; 114 115char incomingMouthByte; 116char outgoingMouthByte; 117int 118 mouthOnOffNew; 119int mouthOnOffOld; 120int mouthOnOffDifference; 121int mouthOnOffAdjusted; 122 // value adjusted by 48 for ascii 123 124char incomingHeadByte; 125char outgoingHeadByte; 126int 127 headOnOffNew; 128int headOnOffOld; 129int headOnOffDifference; 130int headOnOffAdjusted; 131 // value adjusted by 48 for ascii 132 133//end declarations 134//end declarations 135//end 136 declarations 137//end declarations 138//end declarations 139//end declarations 140//end 141 declarations 142//end declarations 143//end declarations 144 145//********************************************************* 146//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 147//********************************************************* 148 149// 150 begin void setup 151// begin void setup 152// begin void setup 153// begin void 154 setup 155// begin void setup 156// begin void setup 157// begin void setup 158// 159 begin void setup 160// begin void setup 161// begin void setup 162// begin void 163 setup 164void setup() { 165Serial.begin(9600); 166Serial1.begin(9600); 167Serial2.begin(9600); 168 169 oldButtonTime = millis(); 170 newButtonTime = millis(); 171 Tft.TFTinit(); // 172 init TFT library 173 TFT_BL_ON; // turn on the background light 174 backLightState 175 = 1; 176 x = 0; 177 y = 0; 178 z = 0; 179 buttonPressed = 4; 180 buttonGroup 181 = 0; 182 183 incomingHeadByte = 1; 184 outgoingHeadByte = 1; // for a bit more 185 talkative serial data 186 headOnOffNew = 1; // stores head state from serial connection 187 188 headOnOffOld = 1; // stores head state from serial connection 189 190 191 incomingMouthByte 192 = 0; 193 outgoingMouthByte = 0; // for a bit more talkative serial data 194 mouthOnOffNew 195 = 1; // stores mouth state from serial connection 196 mouthOnOffOld = 1; // stores 197 mouth state from serial connection 198 199 200 //////////////////////////////// 201 202 //// manually set variables //// 203 //////////////////////////////// 204 205 206 debounceTime = 1000; // button debounce in milliseconds 207 zMax 208 = 460; // maximum pressure to detect 209 zMin = 100; // minimum pressure 210 to detect 211 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 212 213 214 215 currentScreen = 0; 216 callScreen(); 217 218} //void setup() 219// end void 220 setup 221// end void setup 222// end void setup 223// end void setup 224// end void 225 setup 226// end void setup 227// end void setup 228// end void setup 229 230//********************************************************* 231//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 232//********************************************************* 233 234// 235 begin void loop 236// begin void loop 237// begin void loop 238// begin void loop 239// 240 begin void loop 241// begin void loop 242// begin void loop 243// begin void loop 244// 245 begin void loop 246// begin void loop 247// begin void loop 248// begin void loop 249// 250 begin void loop 251// begin void loop 252 253void loop() { 254 255 tftBacklightTimeout(); 256 // check time and turn off backlight 257 258 if(buttonGroup == 0){ // most regular 259 pages 260 tftButtonGroup0(); // gather information from touch screen touches 261 262 buttonTimeDifference = newButtonTime - oldButtonTime; 263 if(debounceTime 264 < buttonTimeDifference){ 265 whatScreen(); 266 callScreen(); 267 oldButtonTime 268 = newButtonTime; 269 showStuff(); // serial prints 270 tftDisplay(); // 271 display x y coordinates on tft display 272 } 273 } 274 if(buttonGroup == 1){ 275 // on off buttons 276 tftButtonGroup1(); // gather information from touch screen 277 touches 278 buttonTimeDifference = newButtonTime - oldButtonTime; 279 if(debounceTime 280 < buttonTimeDifference){ 281 whatScreen(); 282 callScreen(); 283 oldButtonTime 284 = newButtonTime; 285 showStuff(); // serial prints 286 tftDisplay(); // 287 display x y coordinates on tft display 288 mouthUnoTxRx(); 289 } 290 } 291 292 if(buttonGroup == 2){ // head buttons 293 tftButtonGroup2(); // gather information 294 from touch screen touches 295 buttonTimeDifference = newButtonTime - oldButtonTime; 296 297 if(debounceTime < buttonTimeDifference){ 298 whatScreen(); 299 callScreen(); 300 301 oldButtonTime = newButtonTime; 302 showStuff(); // serial prints 303 304 tftDisplay(); // display x y coordinates on tft display 305 headUnoTxRx(); 306 307 } 308 } 309 310 311} //void loop() 312 313// end of void loop 314// end of 315 void loop 316// end of void loop 317// end of void loop 318// end of void loop 319// 320 end of void loop 321// end of void loop 322// end of void loop 323// end of void 324 loop 325// end of void loop 326// end of void loop 327// end of void loop 328// 329 end of void loop 330// end of void loop 331// end of void loop 332 333//**************************************************************************************************** 334//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 335//**************************************************************************************************** 336///////////////////////////////////////////////////////////////////////////////////////////////////////// 337///////////////////////////////////////// 338 functions /////////////////////////////////////////////////// 339///////////////////////////////////////////////////////////////////////////////////////////////////////// 340//**************************************************************************************************** 341//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 342//**************************************************************************************************** 343 344//--------------------------begin 345 tftBacklightTimeout---------------------------------- 346void tftBacklightTimeout(){ 347 348 newBacklightTime = millis(); 349 if(backLightState = 0){ 350 backlightTimeDifference 351 = newBacklightTime - oldBacklightTime; 352 if(backlightTimer > backlightTimeDifference){ 353 354 backlightTimeDifference = newBacklightTime - oldBacklightTime; 355 TFT_BL_ON; 356 // turn on the background light 357 backLightState = 1; 358 oldBacklightTime 359 = millis(); 360 } 361 } 362 if(backLightState = 1){ 363 backlightTimeDifference 364 = newBacklightTime - oldBacklightTime; 365 if(backlightTimer < backlightTimeDifference){ 366 367 backlightTimeDifference = newBacklightTime - oldBacklightTime; 368 TFT_BL_OFF; 369 // turn off the background light 370 backLightState = 0; 371 oldBacklightTime 372 = millis(); 373 } 374 } 375} 376//--------------------------end tftBacklightTimeout---------------------------------- 377 378//**************************************************************************************************** 379//**************************************************************************************************** 380 381//--------------------------begin 382 tftButtonGroup0---------------------------------- 383//--------------------------begin 384 tftButtonGroup0---------------------------------- 385//--------------------------begin 386 tftButtonGroup0---------------------------------- 387//--------------------------begin 388 tftButtonGroup0---------------------------------- 389int tftButtonGroup0(){ 390 391 Point p = ts.getPoint(); 392 if(zMin<p.z && p.z<zMax){ 393 TFT_BL_ON; // 394 turn on the background light 395 backLightState = 1; 396 oldBacklightTime 397 = millis(); 398 newButtonTime = millis(); 399 p.x = map(p.x, TS_MINX, TS_MAXX, 400 0, 240); 401 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 402//Button 1 403 if(75<p.x 404 && p.x<140){ 405 if(100<p.y && p.y<164){ 406 buttonPressed = 1; 407 408 } 409//Button 2 410 if(164<p.y && p.y<240){ 411 buttonPressed 412 = 2; 413 } 414//Button 3 415 if(240<p.y && p.y<310){ 416 buttonPressed 417 = 3; 418 } 419 } 420 } 421//Button 4 422 if(10<p.x && p.x<75){ 423 424 if(100<p.y && p.y<240){ 425 buttonPressed = 4; 426 } 427 428 } 429}//void tftButtonGroup0 430//--------------------------end tftButtonGroup0 431 code---------------------------------- 432//--------------------------end tftButtonGroup0 433 code---------------------------------- 434//--------------------------end tftButtonGroup0 435 code---------------------------------- 436//--------------------------end tftButtonGroup0 437 code---------------------------------- 438//--------------------------end tftButtonGroup0 439 code---------------------------------- 440//**************************************************************************************************** 441//**************************************************************************************************** 442 443//--------------------------begin 444 tftButtonGroup1---------------------------------- 445//--------------------------begin 446 tftButtonGroup1---------------------------------- 447//--------------------------begin 448 tftButtonGroup1---------------------------------- 449//--------------------------begin 450 tftButtonGroup1---------------------------------- 451int tftButtonGroup1(){ // 452 for mouth 453buttonPressed = 0; 454 Point p = ts.getPoint(); 455 if(zMin<p.z && 456 p.z<zMax){ 457 TFT_BL_ON; // turn on the background light 458 backLightState 459 = 1; 460 oldBacklightTime = millis(); 461 newButtonTime = millis(); 462 463 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 464 p.y = map(p.y, TS_MINY, TS_MAXY, 465 0, 320); 466//Button 1 467 if(75<p.x && p.x<140){ 468 if(100<p.y && p.y<164){ 469 470 mouthOnOffNew = 1; // on 471 Serial.print("mouthOnOffNew set to 472 "); 473 Serial.println(mouthOnOffNew); 474 } 475//Button 2 476 477 if(164<p.y && p.y<240){ 478 mouthOnOffNew = 2; // off 479 Serial.print("mouthOnOffNew 480 set to "); 481 Serial.println(mouthOnOffNew); 482 } 483//Button 3 484// 485 if(240<p.y && p.y<310){ 486// buttonPressed = 3; 487// } 488 489 } 490 } 491//Button 4 492 if(10<p.x && p.x<75){ 493 if(100<p.y 494 && p.y<240){ 495 buttonPressed = 4; 496 buttonGroup = 0; 497 } 498 499 } 500}//void tftButtonGroup1 501//--------------------------end tftButtonGroup1 502 code---------------------------------- 503//--------------------------end tftButtonGroup1 504 code---------------------------------- 505//--------------------------end tftButtonGroup1 506 code---------------------------------- 507//--------------------------end tftButtonGroup1 508 code---------------------------------- 509//--------------------------end tftButtonGroup1 510 code---------------------------------- 511//**************************************************************************************************** 512//**************************************************************************************************** 513 514//--------------------------begin 515 tftButtonGroup2---------------------------------- 516//--------------------------begin 517 tftButtonGroup2---------------------------------- 518//--------------------------begin 519 tftButtonGroup2---------------------------------- 520//--------------------------begin 521 tftButtonGroup2---------------------------------- 522int tftButtonGroup2(){ // 523 for mouth 524buttonPressed = 0; 525 Point p = ts.getPoint(); 526 if(zMin<p.z && 527 p.z<zMax){ 528 TFT_BL_ON; // turn on the background light 529 backLightState 530 = 1; 531 oldBacklightTime = millis(); 532 newButtonTime = millis(); 533 534 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 535 p.y = map(p.y, TS_MINY, TS_MAXY, 536 0, 320); 537//Button 1 538 if(75<p.x && p.x<140){ 539 if(100<p.y && p.y<164){ 540 541 headOnOffNew = 1; // on 542 Serial.print("headOnOffNew set to "); 543 544 Serial.println(headOnOffNew); 545 } 546//Button 2 547 if(164<p.y 548 && p.y<240){ 549 headOnOffNew = 2; // off 550 Serial.print("headOnOffNew 551 set to "); 552 Serial.println(headOnOffNew); 553 } 554//Button 3 555// 556 if(240<p.y && p.y<310){ 557// buttonPressed = 3; 558// } 559 560 } 561 } 562//Button 4 563 if(10<p.x && p.x<75){ 564 if(100<p.y 565 && p.y<240){ 566 buttonPressed = 4; 567 buttonGroup = 0; 568 } 569 570 } 571}//void tftButtonGroup2 572//--------------------------end tftButtonGroup2 573 code---------------------------------- 574//--------------------------end tftButtonGroup2 575 code---------------------------------- 576//--------------------------end tftButtonGroup2 577 code---------------------------------- 578//--------------------------end tftButtonGroup2 579 code---------------------------------- 580//--------------------------end tftButtonGroup2 581 code---------------------------------- 582//**************************************************************************************************** 583//**************************************************************************************************** 584//-------------------------- 585 begin whatScreen function ------------------------- 586//-------------------------- 587 begin whatScreen function ------------------------- 588//-------------------------- 589 begin whatScreen function ------------------------- 590//-------------------------- 591 begin whatScreen function ------------------------- 592 593int whatScreen(){ 594 595 if(x == 0){ 596 if(buttonPressed == 1){ 597 x = x + 1; 598 Serial.println("x 599 + 1"); 600 } 601 if(buttonPressed == 2){ 602 x = x + 2; 603 Serial.println("x 604 + 2"); 605 } 606 if(buttonPressed == 3){ 607 x = x + 3; 608 Serial.println("x 609 + 3"); 610 } 611 if(buttonPressed == 4){ 612 x = 0; 613 Serial.println("x 614 = 0"); 615 } 616 if(buttonPressed == 5){ 617 x = 0; 618 y 619 = 0; 620 z = 0; 621 Serial.println("xyz all 0"); 622 } 623 624 } 625 else if(x >> 0){ 626 if(y == 0){ 627 if(buttonPressed == 628 1){ 629 y = y + 10; 630 Serial.println("y + 10"); 631 } 632 633 if(buttonPressed == 2){ 634 y = y + 20; 635 Serial.println("y 636 + 20"); 637 } 638 if(buttonPressed == 3){ 639 y = y + 30; 640 641 Serial.println("y + 30"); 642 } 643 if(buttonPressed == 644 4){ 645 x = 0; 646 Serial.println("x = 0"); 647 } 648 649 if(buttonPressed == 5){ 650 x = 0; 651 y = 0; 652 z 653 = 0; 654 Serial.println("xyz all 0"); 655 } 656 } 657 else 658 if (y >> 0){ 659 if(buttonPressed == 1){ 660 z = z + 100; 661 662 Serial.println("z + 100"); 663 } 664 if(buttonPressed 665 == 2){ 666 z = z + 200; 667 Serial.println("z + 200"); 668 669 } 670 if(buttonPressed == 3){ 671 z = z + 300; 672 673 Serial.println("z + 300"); 674 } 675 if(buttonPressed 676 == 4){ 677 if(z == 0){ 678 y = 0; 679 Serial.println("y 680 = 0"); 681 } 682 else if(z >> 0){ 683 z = 0; 684 685 Serial.println("z = 0"); 686 } 687 } 688 if(buttonPressed 689 == 5){ 690 x = 0; 691 y = 0; 692 z = 0; 693 Serial.println("xyz 694 all 0"); 695 } 696 }//y>0 697 }//x>0 698 currentScreen = 699 z+y+x; 700 if(currentScreen == 122){ 701 buttonGroup=1; 702 } 703 if(currentScreen 704 == 222){ 705 buttonGroup=1; 706 } 707 if(currentScreen == 23){ 708 buttonGroup=2; 709 710 } 711} 712//-------------------------- end whatScreen function ------------------------- 713//-------------------------- 714 end whatScreen function ------------------------- 715//-------------------------- 716 end whatScreen function ------------------------- 717//-------------------------- 718 end whatScreen function ------------------------- 719//-------------------------- 720 end whatScreen function ------------------------- 721 722//**************************************************************************************************** 723//**************************************************************************************************** 724 725//--------------------------begin 726 mouthUnoTxRx---------------------------------- 727 728void mouthUnoTxRx(){ 729 if(mouthOnOffNew 730 != mouthOnOffOld){ 731 Serial.println("starting txrx"); 732 if(mouthOnOffNew 733 == 1){ 734 Serial.println("Starting tx"); 735 Serial1.flush(); 736 Serial1.write('1'); 737 738 mouthOnOffOld = 1; 739//begin rx 740 Serial.println("Starting rx"); 741 742 743 delay(10); // tweak delay to accomodate uno 744 745 // use a serial 746 available after flush funtion while or for loop or interrrupt or somethin 747 incomingMouthByte 748 = Serial1.read(); 749 Serial1.flush(); 750 mouthOnOffAdjusted = incomingMouthByte; 751 752 Serial.print("mouthOnOffAdjusted should be 1: "); 753 Serial.println(mouthOnOffAdjusted); 754 755 } 756 if(mouthOnOffNew == 2){ 757 Serial.println("Starting tx"); 758 759 Serial1.flush(); 760 Serial1.write('2'); 761 mouthOnOffOld = 2; 762//begin 763 rx 764 Serial.println("Starting rx"); 765 766 delay(10); // tweak delay 767 to accomodate uno 768 769 incomingMouthByte = Serial1.read(); 770 Serial1.flush(); 771 772 mouthOnOffAdjusted = incomingMouthByte; 773 Serial.print("mouthOnOffAdjusted 774 should be 2: "); 775 Serial.println(mouthOnOffAdjusted); 776 } 777 else 778 if(mouthOnOffAdjusted != 1 && mouthOnOffAdjusted != 2){ 779 Serial.println("error 780 reply wasn't like expected"); 781 Serial.print("instead, the adjusted reply 782 was"); 783 784 delay(10); // tweak delay to accomodate uno 785 786 incomingMouthByte 787 = Serial1.read(); 788 Serial1.flush(); 789 mouthOnOffAdjusted = incomingMouthByte; 790 791 Serial.print("mouthOnOffAdjusted: "); 792 Serial.println(mouthOnOffAdjusted); 793 794 } 795 } 796 else if(mouthOnOffOld = mouthOnOffNew){ 797 } 798 Serial.flush(); 799 800 Serial1.flush(); 801} 802 803//--------------------------end mouthUnoTxRx -------------------------------------- 804//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 805//--------------------------begin 806 headUnoTxRx---------------------------------- 807 808void headUnoTxRx(){ 809 if(headOnOffNew 810 != headOnOffOld){ 811 Serial.println("starting txrx"); 812 if(headOnOffNew 813 == 1){ 814 Serial.println("Starting tx"); 815 Serial2.flush(); 816 Serial2.write('1'); 817 818 headOnOffOld = 1; 819//begin rx 820 Serial.println("Starting rx"); 821 822 823 delay(10); // tweak delay to accomodate uno 824 825 // use a serial 826 available after flush funtion while or for loop or interrrupt or somethin instead 827 of delay 828 incomingHeadByte = Serial2.read(); 829 Serial2.flush(); 830 831 headOnOffAdjusted = incomingHeadByte; 832 Serial.print("headOnOffAdjusted 833 should be 1: "); 834 Serial.println(headOnOffAdjusted); 835 } 836 if(headOnOffNew 837 == 2){ 838 Serial.println("Starting tx"); 839 Serial2.flush(); 840 Serial2.write('2'); 841 842 headOnOffOld = 2; 843//begin rx 844 Serial.println("Starting rx"); 845 846 847 delay(10); // tweak delay to accomodate uno 848 849 incomingHeadByte 850 = Serial2.read(); 851 Serial2.flush(); 852 headOnOffAdjusted = incomingHeadByte; 853 854 Serial.print("headOnOffAdjusted should be 2: "); 855 Serial.println(headOnOffAdjusted); 856 857 } 858 else if(headOnOffAdjusted != 1 && headOnOffAdjusted != 2){ 859 Serial.println("error 860 reply wasn't like expected"); 861 Serial.print("instead, the adjusted reply 862 was"); 863 864 delay(10); // tweak delay to accomodate uno 865 866 incomingHeadByte 867 = Serial2.read(); 868 Serial2.flush(); 869 headOnOffAdjusted = incomingHeadByte; 870 871 Serial.print("headOnOffAdjusted: "); 872 Serial.println(headOnOffAdjusted); 873 874 } 875 } 876 else if(headOnOffOld = headOnOffNew){ 877 } 878 Serial.flush(); 879 880 Serial2.flush(); 881} 882 883//--------------------------end headUnoTxRx -------------------------------------- 884//**************************************************************************************************** 885//**************************************************************************************************** 886 887//--------------------------begin 888 tftDisplay code---------------------------------- 889void tftDisplay(){ 890 Point 891 p = ts.getPoint(); 892 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 893 p.y = map(p.y, 894 TS_MINY, TS_MAXY, 0, 320); 895 896 Tft.fillRectangle(70, 100, 60, 30, BLACK); 897 898 Tft.drawNumber((buttonGroup), 70, 100, 3, GREEN); 899 Tft.fillRectangle(140, 900 100, 60, 30, BLACK); 901 Tft.drawNumber((mouthOnOffNew), 140, 100, 3, GREEN); 902 903 Tft.fillRectangle(160, 100, 60, 30, BLACK); 904 Tft.drawNumber((headOnOffNew), 905 160, 100, 3, GREEN); 906 Tft.fillRectangle(0, 225, 60, 30, BLACK); 907 Tft.drawNumber((p.x), 908 0, 225, 3, GREEN); 909 Tft.fillRectangle(180, 225, 60, 30, BLACK); 910 Tft.drawNumber((p.y), 911 180, 225, 3, GREEN); 912 Tft.fillRectangle(100, 225, 60, 30, BLACK); 913 Tft.drawNumber((buttonPressed), 914 100, 225, 3, GREEN); 915 Tft.fillRectangle(120, 290, 60, 30, BLACK); 916 Tft.drawNumber((currentScreen), 917 120, 290, 3, GREEN); 918 919 920}// void tftDisplay 921//--------------------------end 922 tftDisplay code------------------------------------ 923 924//**************************************************************************************************** 925//**************************************************************************************************** 926 927//-------------------------- 928 begin mouth on off function -------------------------- 929//-------------------------- 930 end mouth on off function -------------------------- 931 932//**************************************************************************************************** 933//**************************************************************************************************** 934 935//-------------------------- 936 begin head on off function -------------------------- 937//-------------------------- 938 end head on off function ------------------------- 939 940//**************************************************************************************************** 941//**************************************************************************************************** 942 943//-------------------------- 944 begin serial display function -------------------------- 945void showStuff(){ 946 947 Serial.println("------/ last update /-------"); 948// Serial.println("------begin 949 display-------"); 950 Serial.print("buttonPressed "); 951 Serial.println(buttonPressed); 952 953 Serial.print("x "); 954 Serial.println(x); 955 Serial.print("y "); 956 957 Serial.println(y); 958 Serial.print("z "); 959 Serial.println(z); 960 Serial.print("currentScreen 961 "); 962 Serial.println(currentScreen); 963// Serial.println("-------end display--------"); 964 965 Serial.println(""); 966 Serial.println(""); 967 Serial.println(""); 968 969 } 970//-------------------------- end serial display function ------------------------- 971 972 973//**************************************************************************************************** 974//**************************************************************************************************** 975 976//--------------------------- 977 Primary screen maps -------------------------------- 978/* 979******** 980updates 981 needed 982******** 9831 ditch the contrast 9842 ditch the brightness 9853 setup 986 screen timeout 987 988 989 990 991screen 0000 A)Home 992 screen 0001 a)settings 993 994 screen 0011 -brightness 995 screen 0011 -contrast 996 screen 0011 -screen 997 lock time out 998 screen 0001 b)sensor monitors 999 screen 0021 -pir 1000 screen 1001 0121 *report pir detection 1002 screen 0021 -sound 1003 screen 0221 *sense 1004 alexa sound 1005 screen 0221 *sense graves sound 1006 screen 0221 *report 1007 mouth servo position 1008 screen 0221 *adjust sensitivity? 1009 screen 0021 1010 -head potentiometer 1011 screen 0021 -bluetooth 1012 screen 0001 c)bluetooth 1013 1014 screen 0031 -on 1015 screen 0031 -off 1016 screen 0031 -monitor 1017screen 1018 0000 B)Mouth Control 1019 screen 0002 a)test button 1020 screen 0012 -open 1021 1022 screen 0012 -close 1023 screen 0012 -push button chicken switch 1024 screen 1025 0002 b)sound sensors on/off 1026 screen 0022 -alexa sense 1027 screen 1028 0122 *on 1029 screen 0122 *off 1030 screen 0122 *monitor sensor 1031 screen 1032 0022 -graves sense 1033 screen 0222 *on 1034 screen 0222 *off 1035 1036 screen 0222 *monitor sensors 1037 screen 0002 c)sound sensor status 1038 1039 screen 0032 -alexa 1040 screen 0032 -graves 1041screen 0000 C)Head Control 1042 1043 screen 0003 a)pir on/off 1044 screen 0013 -on 1045 screen 0013 -off 1046 1047 screen 0013 -sensor 1048 screen 0003 b)manual point 1049 screen 0023 -slider 1050*/ 1051//**************************************************************************************************** 1052//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 1053//**************************************************************************************************** 1054//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1055//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1056 screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1057//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1058//**************************************************************************************************** 1059//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 1060//**************************************************************************************************** 1061 1062//-------------------------- 1063 begin callScreen function ------------------------- 1064//-------------------------- 1065 begin callScreen function ------------------------- 1066//-------------------------- 1067 begin callScreen function ------------------------- 1068//-------------------------- 1069 begin callScreen function ------------------------- 1070//-------------------------- 1071 begin callScreen function ------------------------- 1072//-------------------------- 1073 begin callScreen function ------------------------- 1074//-------------------------- 1075 begin callScreen function ------------------------- 1076//-------------------------- 1077 begin callScreen function ------------------------- 1078//-------------------------- 1079 begin callScreen function ------------------------- 1080//-------------------------- 1081 begin callScreen function ------------------------- 1082//-------------------------- 1083 begin callScreen function ------------------------- 1084 1085int callScreen(){ 1086 1087 Tft.fillRectangle(0, 0, 240, 320, BLACK); 1088 1089//<><><><><><><><><><><><><><><><><><><><><><><><> 1090//<><><><><><><><> 1091 begin screen 0000 master <><><><><><><><> 1092//<><><><><><><><><><><><><><><><><><><><><><><><> 1093if(currentScreen 1094 == 0){ 1095 // " " 1096 Tft.drawString("GRAVES",0,5,4, 1097 GREEN); 1098 Tft.drawString("INTERFACE",10,50,4,GREEN); 1099 Tft.drawString("Home", 1100 80,130, 3, GREEN); 1101 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 1102 1103 Tft.drawString("Head Control", 10, 260, 3, GREEN); 1104} 1105//<><><><><><><><><><><><><><><><><><><><><><><><> 1106//<><><><><><><><> 1107 end screen 0000 master <><><><><><><><><> 1108//<><><><><><><><><><><><><><><><><><><><><><><><> 1109 1110//<><><><><><><><><><><><><><><><><><><><><><><><> 1111//<><><><><><><><> 1112 begin screen 0001 <><><><><><><><> 1113//<><><><><><><><><><><><><><><><><><><><><><><><> 1114 1115 if(currentScreen == 1){ 1116 // " " 1117 Tft.drawString("MEGA 1118 2560",00,5,4,BLUE); 1119 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 1120 Tft.drawString("Settings", 1121 10,130, 3, BLUE); 1122 Tft.drawString("Sensors", 20, 195, 3, BLUE); 1123 Tft.drawString("Bluetooth", 1124 00, 260, 3, BLUE); 1125 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1126} 1127//<><><><><><><><><><><><><><><><><><><><><><><><> 1128//<><><><><><><><> 1129 end screen 0001 <><><><><><><><><> 1130//<><><><><><><><><><><><><><><><><><><><><><><><> 1131 1132//<><><><><><><><><><><><><><><><><><><><><><><><> 1133//<><><><><><><><> 1134 begin screen 0011 <><><><><><><><> 1135//<><><><><><><><><><><><><><><><><><><><><><><><> 1136 1137 if(currentScreen == 11){ 1138 // " " 1139 Tft.drawString("MEGA 1140 2560",00,5,4,BLUE); 1141 Tft.drawString("SETTINGS",10,50,4,YELLOW); 1142 Tft.drawString("Brightness", 1143 80,130, 3, BLUE); 1144 Tft.drawString("Contrast", 05, 195, 3, GREEN); 1145 1146 Tft.drawString("Timeout", 10, 260, 3, GREEN); 1147 Tft.drawString("<", 1148 0, 160, 3, GREEN); // back button 1149} 1150 1151//<><><><><><><><><><><><><><><><><><><><><><><><> 1152//<><><><><><><><> 1153 end screen 0011 <><><><><><><><><> 1154//<><><><><><><><><><><><><><><><><><><><><><><><> 1155 1156//<><><><><><><><><><><><><><><><><><><><><><><><> 1157//<><><><><><><><> 1158 begin screen 0021 <><><><><><><><> 1159//<><><><><><><><><><><><><><><><><><><><><><><><> 1160 1161 if(currentScreen == 21){ 1162 // " " 1163 Tft.drawString("MEGA 1164 2560",00,5,4,BLUE); 1165 Tft.drawString("SENSORS",10,50,4,YELLOW); 1166 Tft.drawString("PIR 1167 Array", 80,130, 3, BLUE); 1168 Tft.drawString("Sound", 05, 195, 3, GREEN); 1169 1170 Tft.drawString("Head Position", 10, 260, 3, GREEN); 1171 Tft.drawString("Bluetooth", 1172 10, 260, 3, GREEN); 1173 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1174} 1175//<><><><><><><><><><><><><><><><><><><><><><><><> 1176//<><><><><><><><> 1177 end screen 0021 <><><><><><><><><> 1178//<><><><><><><><><><><><><><><><><><><><><><><><> 1179 1180//<><><><><><><><><><><><><><><><><><><><><><><><> 1181//<><><><><><><><> 1182 begin screen 0121 <><><><><><><><> 1183//<><><><><><><><><><><><><><><><><><><><><><><><> 1184 1185 if(currentScreen == 121){ 1186 // " " 1187 Tft.drawString("PIR",0,5,4,BLUE); 1188 1189 Tft.drawString("ARRAY",10,50,4,YELLOW); 1190 Tft.drawString("PIR sensor 1191 #", 80, 60, 3, BLUE); 1192 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 1193 1194 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 1195 Tft.drawString("PIR 1196 sensor #", 80, 130, 3, BLUE); 1197 Tft.drawString("PIR sensor #", 80, 130, 1198 3, BLUE); 1199 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 1200 Tft.drawString("<", 1201 0, 160, 3, GREEN); // back button 1202} 1203//<><><><><><><><><><><><><><><><><><><><><><><><> 1204//<><><><><><><><> 1205 end screen 0121 <><><><><><><><><> 1206//<><><><><><><><><><><><><><><><><><><><><><><><> 1207 1208//<><><><><><><><><><><><><><><><><><><><><><><><> 1209//<><><><><><><><> 1210 begin screen 0221 <><><><><><><><> 1211//<><><><><><><><><><><><><><><><><><><><><><><><> 1212 1213 if(currentScreen == 221){ 1214 // " " 1215 Tft.drawString("SOUND",0,5,4,BLUE); 1216 1217 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 1218 Tft.drawString("Sense 1219 Graves", 80,130, 3, BLUE); 1220 Tft.drawString("Jaw position", 05, 195, 3, 1221 GREEN); 1222 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 1223 Tft.drawString("<", 1224 0, 160, 3, GREEN); // back button 1225} 1226//<><><><><><><><><><><><><><><><><><><><><><><><> 1227//<><><><><><><><> 1228 end screen 0221 <><><><><><><><><> 1229//<><><><><><><><><><><><><><><><><><><><><><><><> 1230 1231//<><><><><><><><><><><><><><><><><><><><><><><><> 1232//<><><><><><><><> 1233 begin screen 0031 <><><><><><><><> 1234//<><><><><><><><><><><><><><><><><><><><><><><><> 1235 1236 if(currentScreen == 31){ 1237 // " " 1238 Tft.drawString("Bluetooth",0,5,4,BLUE); 1239 1240 Tft.drawString("Control",10,50,4,YELLOW); 1241 Tft.drawString("On", 1242 80,130, 3, BLUE); 1243 Tft.drawString("Off", 05, 195, 3, GREEN); 1244 Tft.drawString("Monitor", 1245 10, 260, 3, GREEN); 1246 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1247} 1248//<><><><><><><><><><><><><><><><><><><><><><><><> 1249//<><><><><><><><> 1250 end screen 0031 <><><><><><><><><> 1251//<><><><><><><><><><><><><><><><><><><><><><><><> 1252 1253//<><><><><><><><><><><><><><><><><><><><><><><><> 1254//<><><><><><><><> 1255 begin screen 0002 <><><><><><><><> 1256//<><><><><><><><><><><><><><><><><><><><><><><><> 1257 1258 if(currentScreen == 2){ 1259 // " " 1260 Tft.drawString("Mouth",0,5,4,BLUE); 1261 1262 Tft.drawString("Control",10,50,4,YELLOW); 1263 Tft.drawString("Test 1264 Jaw", 80,130, 3, BLUE); 1265 Tft.drawString("Sensor on/off", 05, 195, 3, 1266 GREEN); 1267 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1268 Tft.drawString("<", 1269 0, 160, 3, GREEN); // back button 1270 } 1271//<><><><><><><><><><><><><><><><><><><><><><><><> 1272//<><><><><><><><> 1273 end screen 0002 <><><><><><><><><> 1274//<><><><><><><><><><><><><><><><><><><><><><><><> 1275 1276 1277//<><><><><><><><><><><><><><><><><><><><><><><><> 1278//<><><><><><><><> 1279 begin screen 0012 <><><><><><><><> 1280//<><><><><><><><><><><><><><><><><><><><><><><><> 1281 1282 if(currentScreen == 12){ 1283 // " " 1284 Tft.drawString("Jaw 1285 Test",0,5,4,BLUE); 1286 Tft.drawString("Operations",10,50,4,YELLOW); 1287 1288 Tft.drawString("Open", 80,130, 3, BLUE); 1289 Tft.drawString("Close", 1290 05, 195, 3, GREEN); 1291 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 1292 1293 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1294} 1295//<><><><><><><><><><><><><><><><><><><><><><><><> 1296//<><><><><><><><> 1297 end screen 0012 <><><><><><><><><> 1298//<><><><><><><><><><><><><><><><><><><><><><><><> 1299 1300 1301//<><><><><><><><><><><><><><><><><><><><><><><><> 1302//<><><><><><><><> 1303 begin screen 0022 <><><><><><><><> 1304//<><><><><><><><><><><><><><><><><><><><><><><><> 1305 1306 if(currentScreen == 22){ 1307 // " " 1308 Tft.drawString("Sound",0,5,4,BLUE); 1309 1310 Tft.drawString("Sensors",10,50,4,YELLOW); 1311 Tft.drawString("Alexa 1312 Sense", 80,130, 3, BLUE); 1313 Tft.drawString("Graves Sense", 05, 195, 3, 1314 GREEN); 1315 Tft.drawString("Monitor", 10, 260, 3, GREEN); 1316 Tft.drawString("<", 1317 0, 160, 3, GREEN); // back button 1318} 1319//<><><><><><><><><><><><><><><><><><><><><><><><> 1320//<><><><><><><><> 1321 end screen 0022 <><><><><><><><><> 1322//<><><><><><><><><><><><><><><><><><><><><><><><> 1323 1324 1325 1326//<><><><><><><><><><><><><><><><><><><><><><><><> 1327//<><><><><><><><> 1328 begin screen 0122 <><><><><><><><> 1329//<><><><><><><><><><><><><><><><><><><><><><><><> 1330 1331 if(currentScreen == 122){ 1332 // " " 1333 Tft.drawString("Alexa 1334 Sense",0,5,4,BLUE); 1335 Tft.drawString("Operations",10,50,4,YELLOW); 1336 1337 Tft.drawString("On", 120, 130, 3, GREEN); 1338 Tft.drawString("Off", 1339 115, 195, 3, RED); 1340 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1341 1342 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1343} 1344//<><><><><><><><><><><><><><><><><><><><><><><><> 1345//<><><><><><><><> 1346 end screen 0122 <><><><><><><><><> 1347//<><><><><><><><><><><><><><><><><><><><><><><><> 1348 1349//<><><><><><><><><><><><><><><><><><><><><><><><> 1350//<><><><><><><><> 1351 begin screen 0222 <><><><><><><><> 1352//<><><><><><><><><><><><><><><><><><><><><><><><> 1353 1354 if(currentScreen == 222){ 1355 // " " 1356 Tft.drawString("Graves 1357 Sense",0,5,4,BLUE); 1358 Tft.drawString("Operations",10,50,4,YELLOW); 1359 1360 Tft.drawString("On", 120, 130, 3, GREEN); 1361 Tft.drawString("Off", 1362 115, 195, 3, RED); 1363 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1364 1365 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1366} 1367//<><><><><><><><><><><><><><><><><><><><><><><><> 1368//<><><><><><><><> 1369 end screen 0222 <><><><><><><><><> 1370//<><><><><><><><><><><><><><><><><><><><><><><><> 1371 1372//<><><><><><><><><><><><><><><><><><><><><><><><> 1373//<><><><><><><><> 1374 begin screen 0032 <><><><><><><><> 1375//<><><><><><><><><><><><><><><><><><><><><><><><> 1376 1377 if(currentScreen == 32){ 1378 // " " 1379 Tft.drawString("Sound 1380 Sense",0,5,4,BLUE); 1381 Tft.drawString("Monitors",10,50,4,YELLOW); 1382 Tft.drawString("Alexa", 1383 80,130, 3, BLUE); 1384 Tft.drawString("Graves", 05, 195, 3, GREEN); 1385 Tft.drawString("<", 1386 0, 160, 3, GREEN); // back button 1387} 1388//<><><><><><><><><><><><><><><><><><><><><><><><> 1389//<><><><><><><><> 1390 end screen 0032 <><><><><><><><><> 1391//<><><><><><><><><><><><><><><><><><><><><><><><> 1392 1393//<><><><><><><><><><><><><><><><><><><><><><><><> 1394//<><><><><><><><> 1395 begin screen 0003 <><><><><><><><> 1396//<><><><><><><><><><><><><><><><><><><><><><><><> 1397 1398 if(currentScreen == 3){ 1399 // " " 1400 Tft.drawString("Head 1401 Control",0,5,4,BLUE); 1402 Tft.drawString("Operations",10,50,4,YELLOW); 1403 1404 Tft.drawString("PIR Array", 80,130, 3, BLUE); 1405 Tft.drawString("Motor 1406 On/Off", 05, 195, 3, GREEN); 1407 Tft.drawString("Manual Point", 10, 260, 1408 3, GREEN); 1409 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1410} 1411//<><><><><><><><><><><><><><><><><><><><><><><><> 1412//<><><><><><><><> 1413 end screen 0003 <><><><><><><><><> 1414//<><><><><><><><><><><><><><><><><><><><><><><><> 1415 1416//<><><><><><><><><><><><><><><><><><><><><><><><> 1417//<><><><><><><><> 1418 begin screen 0013 <><><><><><><><> 1419//<><><><><><><><><><><><><><><><><><><><><><><><> 1420 1421 if(currentScreen == 13){ 1422 // " " 1423 Tft.drawString("PIR 1424 Control",0,5,4,BLUE); 1425 Tft.drawString("Operations",10,50,4,YELLOW); 1426 1427 Tft.drawString("On", 80,130, 3, BLUE); 1428 Tft.drawString("Off", 1429 05, 195, 3, GREEN); 1430 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 1431 1432 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1433} 1434//<><><><><><><><><><><><><><><><><><><><><><><><> 1435//<><><><><><><><> 1436 end screen 0013 <><><><><><><><><> 1437//<><><><><><><><><><><><><><><><><><><><><><><><> 1438 1439//<><><><><><><><><><><><><><><><><><><><><><><><> 1440//<><><><><><><><> 1441 begin screen 0023 <><><><><><><><> 1442//<><><><><><><><><><><><><><><><><><><><><><><><> 1443 1444 if(currentScreen == 23){ 1445 // " " 1446 Tft.drawString("Graves 1447 Head",0,5,3,BLUE); 1448 Tft.drawString("Operations",10,50,3,YELLOW); 1449 1450 Tft.drawString("On", 120, 130, 3, GREEN); 1451 Tft.drawString("Off", 1452 115, 195, 3, RED); 1453// Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1454 1455 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1456} 1457//<><><><><><><><><><><><><><><><><><><><><><><><> 1458//<><><><><><><><> 1459 end screen 0023 <><><><><><><><><> 1460//<><><><><><><><><><><><><><><><><><><><><><><><> 1461 1462 1463//<><><><><><><><><><><><><><><><><><><><><><><><> 1464//<><><><><><><><> 1465 begin screen 0422 <><><><><><><><> 1466//<><><><><><><><><><><><><><><><><><><><><><><><> 1467 1468 if(currentScreen == 422){ 1469 // " " 1470 Tft.drawString("Command 1471 Sent",0,5,3,BLUE); 1472 Tft.drawString("Press Back to",0,55,3,YELLOW); 1473 1474 Tft.drawString("Contiue", 50,105, 3, BLUE); 1475 Tft.drawString("<", 1476 0, 160, 3, GREEN); // back button 1477} 1478//<><><><><><><><><><><><><><><><><><><><><><><><> 1479//<><><><><><><><> 1480 end screen 0422 <><><><><><><><><> 1481//<><><><><><><><><><><><><><><><><><><><><><><><> 1482 1483 1484////<><><><><><><><><><><><><><><><><><><><><><><><> 1485////<><><><><><><><> 1486 begin screen lost <><><><><><><><> 1487////<><><><><><><><><><><><><><><><><><><><><><><><> 1488// 1489 else if(currentScreen){ 1490// // " " 1491// 1492 Tft.drawString("Screen not",0,5,3,BLUE); 1493// Tft.drawString("found. 1494 Please",40,50,3,YELLOW); 1495// Tft.drawString("use the back", 80,130, 3, 1496 BLUE); 1497// Tft.drawString("button to", 05, 195, 3, GREEN); 1498// Tft.drawString("return 1499 to fun", 10, 260, 3, GREEN); 1500// Tft.drawString("<", 0, 160, 3, GREEN); 1501 // back button 1502//} 1503////<><><><><><><><><><><><><><><><><><><><><><><><> 1504////<><><><><><><><> 1505 end screen lost <><><><><><><><><> 1506////<><><><><><><><><><><><><><><><><><><><><><><><> 1507 1508}// 1509 callScreen 1510//-------------------------- end callScreen function ------------------------- 1511//-------------------------- 1512 end callScreen function ------------------------- 1513//-------------------------- 1514 end callScreen function ------------------------- 1515//-------------------------- 1516 end callScreen function ------------------------- 1517//-------------------------- 1518 end callScreen function ------------------------- 1519//-------------------------- 1520 end callScreen function ------------------------- 1521//-------------------------- 1522 end callScreen function ------------------------- 1523//-------------------------- 1524 end callScreen function ------------------------- 1525//-------------------------- 1526 end callScreen function ------------------------- 1527//-------------------------- 1528 end callScreen function ------------------------- 1529//-------------------------- 1530 end callScreen function ------------------------- 1531//-------------------------- 1532 end callScreen function ------------------------- 1533//-------------------------- 1534 end callScreen function ------------------------- 1535 1536 1537//**************************************************************************************************** 1538//**************************************************************************************************** 1539 1540 1541 1542 1543 1544 1545 1546//**************************************************************************************************** 1547//**************************************************************************************************** 1548 1549// 1550 fin
Torture works!
c_cpp
And by that, I mean I tortured myself for days trying to get the mega to talk to the uno... then to get the uno to listen... then to get the uno to get the right message without changing it all around just to f with me... then to get the uno to talk back... then to get the mega to listen and understand. it all comes down to two major headaches. by trying to shortcut some intermediate programming, a whole of problems opens up for folks with crap knowledge so far like me. Timing a delay to wait for a response and getting the character data type to work around ascii tables makes my brain hurt
1/* 2last edit thursday oct 18 2018 3working on serial coms 4 5 6gravesmegamaster 7 8graves 9 project 10arduino MEGA 2650 11Master 12coded from scratch by wylie jones 13wyliejones@gmail.com 14 15Graves 16 multi arduino build 10/2018 17Arduino mega 2560 with 240/320 tft and micro sd card 18 (for storing screen backgrounds) 19two arduino uno's 20slave1 arduino uno to sense 21 sound from graves and echo dot to control mouth 22slave2 arduino uno to control 23 passive sensor array and head servo 24 25sound is sensed with a simple DC bias 26 circuit to capture line level input to be used as a digital signal 27 28 analogue 29 pin speaker + 30 \ / 31 (red from speaker) 32 \ / 33 \\ 34 / 35 *--------[=]-----------*---------[=]----------* 36 37 | resistor \ resistor | 38 | \\ 39 | 40 |(red with white) \ |to arduino 41 ground (black with white) 42to arduino 5v+ speaker - 43 (black 44 from speaker) 45 46*/ 47//end notes 48//end notes 49//end notes 50//end notes 51//end 52 notes 53//end notes 54 55 56//********************************************************* 57//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 58//********************************************************* 59 60 61//begin 62 declarations 63//begin declarations 64//begin declarations 65//begin declarations 66//begin 67 declarations 68//begin declarations 69//begin declarations 70 71//#include <TFT.h> 72//#include 73 <Servo.h> 74//#include <stdint.h> 75//#include <SD.h> 76#include <TFTv2.h> 77#include 78 <SPI.h> 79#include <SeeedTouchScreen.h> 80//#include <Wire.h> 81 82//const 83 int PIN_SD_CS = 4; // pin of sd card 84 85TouchScreen ts 86 = TouchScreen(XP, YP, XM, YM); 87int zMax; // maximum pressure to detect 88int 89 zMin; // minimum pressure to detect 90 91int buttonPressed; // stores which button 92 was pressed 93unsigned long newButtonTime; // debounce 94unsigned long oldButtonTime; 95 // debounce 96unsigned long buttonTimeDifference; // debounce 97unsigned long 98 debounceTime; // debounce 99int buttonGroup; // sets kinds of buttons on screen 100 101int 102 currentScreen; // identifies current screen by adding x y and z 103int x; // for 104 ones 105int y; // for tens 106int z; // for hundreds 107 108unsigned long backlightTimer; 109 // for backlight timeout 110int backLightState; // status of backlight 1 for on 111 and 0 for off 112unsigned long backlightTimeDifference; 113unsigned long newBacklightTime; 114unsigned 115 long oldBacklightTime; 116 117char incomingMouthByte; 118char outgoingMouthByte; 119int 120 mouthOnOffNew; 121int mouthOnOffOld; 122int mouthOnOffDifference; 123int mouthOnOffAdjusted; 124 // value adjusted by 48 for ascii 125 126char incomingHeadByte; 127char outgoingHeadByte; 128int 129 headOnOffNew; 130int headOnOffOld; 131int headOnOffDifference; 132int headOnOffAdjusted; 133 // value adjusted by 48 for ascii 134 135//end declarations 136//end declarations 137//end 138 declarations 139//end declarations 140//end declarations 141//end declarations 142//end 143 declarations 144//end declarations 145//end declarations 146 147//********************************************************* 148//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 149//********************************************************* 150 151// 152 begin void setup 153// begin void setup 154// begin void setup 155// begin void 156 setup 157// begin void setup 158// begin void setup 159// begin void setup 160// 161 begin void setup 162// begin void setup 163// begin void setup 164// begin void 165 setup 166void setup() { 167Serial.begin(9600); 168Serial1.begin(9600); 169Serial2.begin(9600); 170 171 oldButtonTime = millis(); 172 newButtonTime = millis(); 173 Tft.TFTinit(); // 174 init TFT library 175 TFT_BL_ON; // turn on the background light 176 backLightState 177 = 1; 178 x = 0; 179 y = 0; 180 z = 0; 181 buttonPressed = 4; 182 buttonGroup 183 = 0; 184 185 incomingHeadByte = 1; 186 outgoingHeadByte = 1; // for a bit more 187 talkative serial data 188 headOnOffNew = 1; // stores head state from serial connection 189 190 headOnOffOld = 1; // stores head state from serial connection 191 192 193 incomingMouthByte 194 = 0; 195 outgoingMouthByte = 0; // for a bit more talkative serial data 196 mouthOnOffNew 197 = 1; // stores mouth state from serial connection 198 mouthOnOffOld = 1; // stores 199 mouth state from serial connection 200 201 202 //////////////////////////////// 203 204 //// manually set variables //// 205 //////////////////////////////// 206 207 208 debounceTime = 1000; // button debounce in milliseconds 209 zMax 210 = 460; // maximum pressure to detect 211 zMin = 100; // minimum pressure 212 to detect 213 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 214 215 216 217 currentScreen = 0; 218 callScreen(); 219 220} //void setup() 221// end void 222 setup 223// end void setup 224// end void setup 225// end void setup 226// end void 227 setup 228// end void setup 229// end void setup 230// end void setup 231 232//********************************************************* 233//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 234//********************************************************* 235 236// 237 begin void loop 238// begin void loop 239// begin void loop 240// begin void loop 241// 242 begin void loop 243// begin void loop 244// begin void loop 245// begin void loop 246// 247 begin void loop 248// begin void loop 249// begin void loop 250// begin void loop 251// 252 begin void loop 253// begin void loop 254 255void loop() { 256 257 tftBacklightTimeout(); 258 // check time and turn off backlight 259 260 if(buttonGroup == 0){ // most regular 261 pages 262 tftButtonGroup0(); // gather information from touch screen touches 263 264 buttonTimeDifference = newButtonTime - oldButtonTime; 265 if(debounceTime 266 < buttonTimeDifference){ 267 whatScreen(); 268 callScreen(); 269 oldButtonTime 270 = newButtonTime; 271 showStuff(); // serial prints 272 tftDisplay(); // 273 display x y coordinates on tft display 274 } 275 } 276 if(buttonGroup == 1){ 277 // on off buttons 278 tftButtonGroup1(); // gather information from touch screen 279 touches 280 buttonTimeDifference = newButtonTime - oldButtonTime; 281 if(debounceTime 282 < buttonTimeDifference){ 283 whatScreen(); 284 callScreen(); 285 oldButtonTime 286 = newButtonTime; 287 showStuff(); // serial prints 288 tftDisplay(); // 289 display x y coordinates on tft display 290 mouthUnoTxRx(); 291 } 292 } 293 294 if(buttonGroup == 2){ // head buttons 295 tftButtonGroup2(); // gather information 296 from touch screen touches 297 buttonTimeDifference = newButtonTime - oldButtonTime; 298 299 if(debounceTime < buttonTimeDifference){ 300 whatScreen(); 301 callScreen(); 302 303 oldButtonTime = newButtonTime; 304 showStuff(); // serial prints 305 306 tftDisplay(); // display x y coordinates on tft display 307 headUnoTxRx(); 308 309 } 310 } 311 312 313} //void loop() 314 315// end of void loop 316// end of 317 void loop 318// end of void loop 319// end of void loop 320// end of void loop 321// 322 end of void loop 323// end of void loop 324// end of void loop 325// end of void 326 loop 327// end of void loop 328// end of void loop 329// end of void loop 330// 331 end of void loop 332// end of void loop 333// end of void loop 334 335//**************************************************************************************************** 336//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 337//**************************************************************************************************** 338///////////////////////////////////////////////////////////////////////////////////////////////////////// 339///////////////////////////////////////// 340 functions /////////////////////////////////////////////////// 341///////////////////////////////////////////////////////////////////////////////////////////////////////// 342//**************************************************************************************************** 343//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 344//**************************************************************************************************** 345 346//--------------------------begin 347 tftBacklightTimeout---------------------------------- 348void tftBacklightTimeout(){ 349 350 newBacklightTime = millis(); 351 if(backLightState = 0){ 352 backlightTimeDifference 353 = newBacklightTime - oldBacklightTime; 354 if(backlightTimer > backlightTimeDifference){ 355 356 backlightTimeDifference = newBacklightTime - oldBacklightTime; 357 TFT_BL_ON; 358 // turn on the background light 359 backLightState = 1; 360 oldBacklightTime 361 = millis(); 362 } 363 } 364 if(backLightState = 1){ 365 backlightTimeDifference 366 = newBacklightTime - oldBacklightTime; 367 if(backlightTimer < backlightTimeDifference){ 368 369 backlightTimeDifference = newBacklightTime - oldBacklightTime; 370 TFT_BL_OFF; 371 // turn off the background light 372 backLightState = 0; 373 oldBacklightTime 374 = millis(); 375 } 376 } 377} 378//--------------------------end tftBacklightTimeout---------------------------------- 379 380//**************************************************************************************************** 381//**************************************************************************************************** 382 383//--------------------------begin 384 tftButtonGroup0---------------------------------- 385//--------------------------begin 386 tftButtonGroup0---------------------------------- 387//--------------------------begin 388 tftButtonGroup0---------------------------------- 389//--------------------------begin 390 tftButtonGroup0---------------------------------- 391int tftButtonGroup0(){ 392 393 Point p = ts.getPoint(); 394 if(zMin<p.z && p.z<zMax){ 395 TFT_BL_ON; // 396 turn on the background light 397 backLightState = 1; 398 oldBacklightTime 399 = millis(); 400 newButtonTime = millis(); 401 p.x = map(p.x, TS_MINX, TS_MAXX, 402 0, 240); 403 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 404//Button 1 405 if(75<p.x 406 && p.x<140){ 407 if(100<p.y && p.y<164){ 408 buttonPressed = 1; 409 410 } 411//Button 2 412 if(164<p.y && p.y<240){ 413 buttonPressed 414 = 2; 415 } 416//Button 3 417 if(240<p.y && p.y<310){ 418 buttonPressed 419 = 3; 420 } 421 } 422 } 423//Button 4 424 if(10<p.x && p.x<75){ 425 426 if(100<p.y && p.y<240){ 427 buttonPressed = 4; 428 } 429 430 } 431}//void tftButtonGroup0 432//--------------------------end tftButtonGroup0 433 code---------------------------------- 434//--------------------------end tftButtonGroup0 435 code---------------------------------- 436//--------------------------end tftButtonGroup0 437 code---------------------------------- 438//--------------------------end tftButtonGroup0 439 code---------------------------------- 440//--------------------------end tftButtonGroup0 441 code---------------------------------- 442//**************************************************************************************************** 443//**************************************************************************************************** 444 445//--------------------------begin 446 tftButtonGroup1---------------------------------- 447//--------------------------begin 448 tftButtonGroup1---------------------------------- 449//--------------------------begin 450 tftButtonGroup1---------------------------------- 451//--------------------------begin 452 tftButtonGroup1---------------------------------- 453int tftButtonGroup1(){ // 454 for mouth 455buttonPressed = 0; 456 Point p = ts.getPoint(); 457 if(zMin<p.z && 458 p.z<zMax){ 459 TFT_BL_ON; // turn on the background light 460 backLightState 461 = 1; 462 oldBacklightTime = millis(); 463 newButtonTime = millis(); 464 465 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 466 p.y = map(p.y, TS_MINY, TS_MAXY, 467 0, 320); 468//Button 1 469 if(75<p.x && p.x<140){ 470 if(100<p.y && p.y<164){ 471 472 mouthOnOffNew = 1; // on 473 Serial.print("mouthOnOffNew set to 474 "); 475 Serial.println(mouthOnOffNew); 476 } 477//Button 2 478 479 if(164<p.y && p.y<240){ 480 mouthOnOffNew = 2; // off 481 Serial.print("mouthOnOffNew 482 set to "); 483 Serial.println(mouthOnOffNew); 484 } 485//Button 3 486// 487 if(240<p.y && p.y<310){ 488// buttonPressed = 3; 489// } 490 491 } 492 } 493//Button 4 494 if(10<p.x && p.x<75){ 495 if(100<p.y 496 && p.y<240){ 497 buttonPressed = 4; 498 buttonGroup = 0; 499 } 500 501 } 502}//void tftButtonGroup1 503//--------------------------end tftButtonGroup1 504 code---------------------------------- 505//--------------------------end tftButtonGroup1 506 code---------------------------------- 507//--------------------------end tftButtonGroup1 508 code---------------------------------- 509//--------------------------end tftButtonGroup1 510 code---------------------------------- 511//--------------------------end tftButtonGroup1 512 code---------------------------------- 513//**************************************************************************************************** 514//**************************************************************************************************** 515 516//--------------------------begin 517 tftButtonGroup2---------------------------------- 518//--------------------------begin 519 tftButtonGroup2---------------------------------- 520//--------------------------begin 521 tftButtonGroup2---------------------------------- 522//--------------------------begin 523 tftButtonGroup2---------------------------------- 524int tftButtonGroup2(){ // 525 for mouth 526buttonPressed = 0; 527 Point p = ts.getPoint(); 528 if(zMin<p.z && 529 p.z<zMax){ 530 TFT_BL_ON; // turn on the background light 531 backLightState 532 = 1; 533 oldBacklightTime = millis(); 534 newButtonTime = millis(); 535 536 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 537 p.y = map(p.y, TS_MINY, TS_MAXY, 538 0, 320); 539//Button 1 540 if(75<p.x && p.x<140){ 541 if(100<p.y && p.y<164){ 542 543 headOnOffNew = 1; // on 544 Serial.print("headOnOffNew set to "); 545 546 Serial.println(headOnOffNew); 547 } 548//Button 2 549 if(164<p.y 550 && p.y<240){ 551 headOnOffNew = 2; // off 552 Serial.print("headOnOffNew 553 set to "); 554 Serial.println(headOnOffNew); 555 } 556//Button 3 557// 558 if(240<p.y && p.y<310){ 559// buttonPressed = 3; 560// } 561 562 } 563 } 564//Button 4 565 if(10<p.x && p.x<75){ 566 if(100<p.y 567 && p.y<240){ 568 buttonPressed = 4; 569 buttonGroup = 0; 570 } 571 572 } 573}//void tftButtonGroup2 574//--------------------------end tftButtonGroup2 575 code---------------------------------- 576//--------------------------end tftButtonGroup2 577 code---------------------------------- 578//--------------------------end tftButtonGroup2 579 code---------------------------------- 580//--------------------------end tftButtonGroup2 581 code---------------------------------- 582//--------------------------end tftButtonGroup2 583 code---------------------------------- 584//**************************************************************************************************** 585//**************************************************************************************************** 586//-------------------------- 587 begin whatScreen function ------------------------- 588//-------------------------- 589 begin whatScreen function ------------------------- 590//-------------------------- 591 begin whatScreen function ------------------------- 592//-------------------------- 593 begin whatScreen function ------------------------- 594 595int whatScreen(){ 596 597 if(x == 0){ 598 if(buttonPressed == 1){ 599 x = x + 1; 600 Serial.println("x 601 + 1"); 602 } 603 if(buttonPressed == 2){ 604 x = x + 2; 605 Serial.println("x 606 + 2"); 607 } 608 if(buttonPressed == 3){ 609 x = x + 3; 610 Serial.println("x 611 + 3"); 612 } 613 if(buttonPressed == 4){ 614 x = 0; 615 Serial.println("x 616 = 0"); 617 } 618 if(buttonPressed == 5){ 619 x = 0; 620 y 621 = 0; 622 z = 0; 623 Serial.println("xyz all 0"); 624 } 625 626 } 627 else if(x >> 0){ 628 if(y == 0){ 629 if(buttonPressed == 630 1){ 631 y = y + 10; 632 Serial.println("y + 10"); 633 } 634 635 if(buttonPressed == 2){ 636 y = y + 20; 637 Serial.println("y 638 + 20"); 639 } 640 if(buttonPressed == 3){ 641 y = y + 30; 642 643 Serial.println("y + 30"); 644 } 645 if(buttonPressed == 646 4){ 647 x = 0; 648 Serial.println("x = 0"); 649 } 650 651 if(buttonPressed == 5){ 652 x = 0; 653 y = 0; 654 z 655 = 0; 656 Serial.println("xyz all 0"); 657 } 658 } 659 else 660 if (y >> 0){ 661 if(buttonPressed == 1){ 662 z = z + 100; 663 664 Serial.println("z + 100"); 665 } 666 if(buttonPressed 667 == 2){ 668 z = z + 200; 669 Serial.println("z + 200"); 670 671 } 672 if(buttonPressed == 3){ 673 z = z + 300; 674 675 Serial.println("z + 300"); 676 } 677 if(buttonPressed 678 == 4){ 679 if(z == 0){ 680 y = 0; 681 Serial.println("y 682 = 0"); 683 } 684 else if(z >> 0){ 685 z = 0; 686 687 Serial.println("z = 0"); 688 } 689 } 690 if(buttonPressed 691 == 5){ 692 x = 0; 693 y = 0; 694 z = 0; 695 Serial.println("xyz 696 all 0"); 697 } 698 }//y>0 699 }//x>0 700 currentScreen = 701 z+y+x; 702 if(currentScreen == 122){ 703 buttonGroup=1; 704 } 705 if(currentScreen 706 == 222){ 707 buttonGroup=1; 708 } 709 if(currentScreen == 23){ 710 buttonGroup=2; 711 712 } 713} 714//-------------------------- end whatScreen function ------------------------- 715//-------------------------- 716 end whatScreen function ------------------------- 717//-------------------------- 718 end whatScreen function ------------------------- 719//-------------------------- 720 end whatScreen function ------------------------- 721//-------------------------- 722 end whatScreen function ------------------------- 723 724//**************************************************************************************************** 725//**************************************************************************************************** 726 727//--------------------------begin 728 mouthUnoTxRx---------------------------------- 729 730void mouthUnoTxRx(){ 731 if(mouthOnOffNew 732 != mouthOnOffOld){ 733 Serial.println("starting txrx"); 734 delay(10); 735 736 if(mouthOnOffNew == 1){ 737 Serial.println("Starting tx"); 738 delay(10); 739 740 Serial1.flush(); 741 Serial1.write('1'); 742 delay(10); 743 mouthOnOffOld 744 = 1; 745//begin rx 746 Serial.println("Starting rx"); 747 delay(4000); 748 // tweak delay to accomodate uno 749 750 // use a serial available after 751 flush funtion while or for loop or interrrupt or somethin 752 incomingMouthByte 753 = Serial1.read(); 754 Serial1.flush(); 755 mouthOnOffAdjusted = incomingMouthByte; 756 757 Serial.print("mouthOnOffAdjusted should be 1: "); 758 Serial.println(mouthOnOffAdjusted); 759 760 } 761 if(mouthOnOffNew == 2){ 762 Serial.println("Starting tx"); 763 764 delay(10); 765 Serial1.flush(); 766 Serial1.write('2'); 767 delay(20); 768 769 mouthOnOffOld = 2; 770//begin rx 771 Serial.println("Starting rx"); 772 773 delay(3000); // tweak delay to accomodate uno 774 incomingMouthByte = 775 Serial1.read(); 776 Serial1.flush(); 777 mouthOnOffAdjusted = incomingMouthByte; 778 779 Serial.print("mouthOnOffAdjusted should be 2: "); 780 Serial.println(mouthOnOffAdjusted); 781 782 } 783 else if(mouthOnOffAdjusted != 1 && mouthOnOffAdjusted != 2){ 784 Serial.println("error 785 reply wasn't like expected"); 786 Serial.print("instead, the adjusted reply 787 was"); 788 delay(6000); // tweak delay to accomodate uno 789 incomingMouthByte 790 = Serial1.read(); 791 Serial1.flush(); 792 mouthOnOffAdjusted = incomingMouthByte; 793 794 Serial.print("mouthOnOffAdjusted: "); 795 Serial.println(mouthOnOffAdjusted); 796 797 } 798 } 799 else if(mouthOnOffOld = mouthOnOffNew){ 800 } 801 Serial.flush(); 802 803 Serial1.flush(); 804} 805 806//--------------------------end mouthUnoTxRx -------------------------------------- 807//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 808//--------------------------begin 809 headUnoTxRx -------------------------------------- 810 811void headUnoTxRx(){ 812 813 if(headOnOffNew != headOnOffOld){ 814 if(headOnOffNew == 1){ 815 Serial2.write('1'); 816 817 Serial.write('1'); 818 headOnOffOld = 1; 819 delay(1000); 820 if(Serial2.available() 821 > 0){ 822 incomingHeadByte = Serial2.read(); 823 headOnOffAdjusted 824 = incomingHeadByte - 48; 825 if(headOnOffAdjusted == 1){ 826 Serial2.write('1'); 827 828 Serial.write('1'); 829 } 830 } 831 } 832 if(headOnOffNew 833 == 2){ 834 Serial2.write('2'); 835 Serial.write('2'); 836 headOnOffOld 837 = 2; 838 delay(1000); 839 if(Serial2.available() > 0){ 840 incomingHeadByte 841 = Serial2.read(); 842 headOnOffAdjusted = incomingHeadByte - 48; 843 if(headOnOffAdjusted 844 == 2){ 845 Serial2.write('2'); 846 Serial.write('2'); 847 848 } 849 } 850 } 851 } 852} 853//--------------------------end headUnoTxRx 854 -------------------------------------- 855 856//**************************************************************************************************** 857//**************************************************************************************************** 858 859//--------------------------begin 860 tftDisplay code---------------------------------- 861void tftDisplay(){ 862 Point 863 p = ts.getPoint(); 864 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 865 p.y = map(p.y, 866 TS_MINY, TS_MAXY, 0, 320); 867 868 Tft.fillRectangle(70, 100, 60, 30, BLACK); 869 870 Tft.drawNumber((buttonGroup), 70, 100, 3, GREEN); 871 Tft.fillRectangle(140, 872 100, 60, 30, BLACK); 873 Tft.drawNumber((mouthOnOffNew), 140, 100, 3, GREEN); 874 875 Tft.fillRectangle(160, 100, 60, 30, BLACK); 876 Tft.drawNumber((headOnOffNew), 877 160, 100, 3, GREEN); 878 Tft.fillRectangle(0, 225, 60, 30, BLACK); 879 Tft.drawNumber((p.x), 880 0, 225, 3, GREEN); 881 Tft.fillRectangle(180, 225, 60, 30, BLACK); 882 Tft.drawNumber((p.y), 883 180, 225, 3, GREEN); 884 Tft.fillRectangle(100, 225, 60, 30, BLACK); 885 Tft.drawNumber((buttonPressed), 886 100, 225, 3, GREEN); 887 Tft.fillRectangle(120, 290, 60, 30, BLACK); 888 Tft.drawNumber((currentScreen), 889 120, 290, 3, GREEN); 890 891 892}// void tftDisplay 893//--------------------------end 894 tftDisplay code------------------------------------ 895 896//**************************************************************************************************** 897//**************************************************************************************************** 898 899//-------------------------- 900 begin mouth on off function -------------------------- 901//-------------------------- 902 end mouth on off function -------------------------- 903 904//**************************************************************************************************** 905//**************************************************************************************************** 906 907//-------------------------- 908 begin head on off function -------------------------- 909//-------------------------- 910 end head on off function ------------------------- 911 912//**************************************************************************************************** 913//**************************************************************************************************** 914 915//-------------------------- 916 begin serial display function -------------------------- 917void showStuff(){ 918 919 Serial.println("------/ last update /-------"); 920// Serial.println("------begin 921 display-------"); 922 Serial.print("buttonPressed "); 923 Serial.println(buttonPressed); 924 925 Serial.print("x "); 926 Serial.println(x); 927 Serial.print("y "); 928 929 Serial.println(y); 930 Serial.print("z "); 931 Serial.println(z); 932 Serial.print("currentScreen 933 "); 934 Serial.println(currentScreen); 935// Serial.println("-------end display--------"); 936 937 Serial.println(""); 938 Serial.println(""); 939 Serial.println(""); 940 941 } 942//-------------------------- end serial display function ------------------------- 943 944 945//**************************************************************************************************** 946//**************************************************************************************************** 947 948//--------------------------- 949 Primary screen maps -------------------------------- 950/* 951******** 952updates 953 needed 954******** 9551 ditch the contrast 9562 ditch the brightness 9573 setup 958 screen timeout 959 960 961 962 963screen 0000 A)Home 964 screen 0001 a)settings 965 966 screen 0011 -brightness 967 screen 0011 -contrast 968 screen 0011 -screen 969 lock time out 970 screen 0001 b)sensor monitors 971 screen 0021 -pir 972 screen 973 0121 *report pir detection 974 screen 0021 -sound 975 screen 0221 *sense 976 alexa sound 977 screen 0221 *sense graves sound 978 screen 0221 *report 979 mouth servo position 980 screen 0221 *adjust sensitivity? 981 screen 0021 982 -head potentiometer 983 screen 0021 -bluetooth 984 screen 0001 c)bluetooth 985 986 screen 0031 -on 987 screen 0031 -off 988 screen 0031 -monitor 989screen 990 0000 B)Mouth Control 991 screen 0002 a)test button 992 screen 0012 -open 993 994 screen 0012 -close 995 screen 0012 -push button chicken switch 996 screen 997 0002 b)sound sensors on/off 998 screen 0022 -alexa sense 999 screen 1000 0122 *on 1001 screen 0122 *off 1002 screen 0122 *monitor sensor 1003 screen 1004 0022 -graves sense 1005 screen 0222 *on 1006 screen 0222 *off 1007 1008 screen 0222 *monitor sensors 1009 screen 0002 c)sound sensor status 1010 1011 screen 0032 -alexa 1012 screen 0032 -graves 1013screen 0000 C)Head Control 1014 1015 screen 0003 a)pir on/off 1016 screen 0013 -on 1017 screen 0013 -off 1018 1019 screen 0013 -sensor 1020 screen 0003 b)manual point 1021 screen 0023 -slider 1022*/ 1023//**************************************************************************************************** 1024//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 1025//**************************************************************************************************** 1026//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1027//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1028 screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1029//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1030//**************************************************************************************************** 1031//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 1032//**************************************************************************************************** 1033 1034//-------------------------- 1035 begin callScreen function ------------------------- 1036//-------------------------- 1037 begin callScreen function ------------------------- 1038//-------------------------- 1039 begin callScreen function ------------------------- 1040//-------------------------- 1041 begin callScreen function ------------------------- 1042//-------------------------- 1043 begin callScreen function ------------------------- 1044//-------------------------- 1045 begin callScreen function ------------------------- 1046//-------------------------- 1047 begin callScreen function ------------------------- 1048//-------------------------- 1049 begin callScreen function ------------------------- 1050//-------------------------- 1051 begin callScreen function ------------------------- 1052//-------------------------- 1053 begin callScreen function ------------------------- 1054//-------------------------- 1055 begin callScreen function ------------------------- 1056 1057int callScreen(){ 1058 1059 Tft.fillRectangle(0, 0, 240, 320, BLACK); 1060 1061//<><><><><><><><><><><><><><><><><><><><><><><><> 1062//<><><><><><><><> 1063 begin screen 0000 master <><><><><><><><> 1064//<><><><><><><><><><><><><><><><><><><><><><><><> 1065if(currentScreen 1066 == 0){ 1067 // " " 1068 Tft.drawString("GRAVES",0,5,4, 1069 GREEN); 1070 Tft.drawString("INTERFACE",10,50,4,GREEN); 1071 Tft.drawString("Home", 1072 80,130, 3, GREEN); 1073 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 1074 1075 Tft.drawString("Head Control", 10, 260, 3, GREEN); 1076} 1077//<><><><><><><><><><><><><><><><><><><><><><><><> 1078//<><><><><><><><> 1079 end screen 0000 master <><><><><><><><><> 1080//<><><><><><><><><><><><><><><><><><><><><><><><> 1081 1082//<><><><><><><><><><><><><><><><><><><><><><><><> 1083//<><><><><><><><> 1084 begin screen 0001 <><><><><><><><> 1085//<><><><><><><><><><><><><><><><><><><><><><><><> 1086 1087 if(currentScreen == 1){ 1088 // " " 1089 Tft.drawString("MEGA 1090 2560",00,5,4,BLUE); 1091 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 1092 Tft.drawString("Settings", 1093 10,130, 3, BLUE); 1094 Tft.drawString("Sensors", 20, 195, 3, BLUE); 1095 Tft.drawString("Bluetooth", 1096 00, 260, 3, BLUE); 1097 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1098} 1099//<><><><><><><><><><><><><><><><><><><><><><><><> 1100//<><><><><><><><> 1101 end screen 0001 <><><><><><><><><> 1102//<><><><><><><><><><><><><><><><><><><><><><><><> 1103 1104//<><><><><><><><><><><><><><><><><><><><><><><><> 1105//<><><><><><><><> 1106 begin screen 0011 <><><><><><><><> 1107//<><><><><><><><><><><><><><><><><><><><><><><><> 1108 1109 if(currentScreen == 11){ 1110 // " " 1111 Tft.drawString("MEGA 1112 2560",00,5,4,BLUE); 1113 Tft.drawString("SETTINGS",10,50,4,YELLOW); 1114 Tft.drawString("Brightness", 1115 80,130, 3, BLUE); 1116 Tft.drawString("Contrast", 05, 195, 3, GREEN); 1117 1118 Tft.drawString("Timeout", 10, 260, 3, GREEN); 1119 Tft.drawString("<", 1120 0, 160, 3, GREEN); // back button 1121} 1122 1123//<><><><><><><><><><><><><><><><><><><><><><><><> 1124//<><><><><><><><> 1125 end screen 0011 <><><><><><><><><> 1126//<><><><><><><><><><><><><><><><><><><><><><><><> 1127 1128//<><><><><><><><><><><><><><><><><><><><><><><><> 1129//<><><><><><><><> 1130 begin screen 0021 <><><><><><><><> 1131//<><><><><><><><><><><><><><><><><><><><><><><><> 1132 1133 if(currentScreen == 21){ 1134 // " " 1135 Tft.drawString("MEGA 1136 2560",00,5,4,BLUE); 1137 Tft.drawString("SENSORS",10,50,4,YELLOW); 1138 Tft.drawString("PIR 1139 Array", 80,130, 3, BLUE); 1140 Tft.drawString("Sound", 05, 195, 3, GREEN); 1141 1142 Tft.drawString("Head Position", 10, 260, 3, GREEN); 1143 Tft.drawString("Bluetooth", 1144 10, 260, 3, GREEN); 1145 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1146} 1147//<><><><><><><><><><><><><><><><><><><><><><><><> 1148//<><><><><><><><> 1149 end screen 0021 <><><><><><><><><> 1150//<><><><><><><><><><><><><><><><><><><><><><><><> 1151 1152//<><><><><><><><><><><><><><><><><><><><><><><><> 1153//<><><><><><><><> 1154 begin screen 0121 <><><><><><><><> 1155//<><><><><><><><><><><><><><><><><><><><><><><><> 1156 1157 if(currentScreen == 121){ 1158 // " " 1159 Tft.drawString("PIR",0,5,4,BLUE); 1160 1161 Tft.drawString("ARRAY",10,50,4,YELLOW); 1162 Tft.drawString("PIR sensor 1163 #", 80, 60, 3, BLUE); 1164 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 1165 1166 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 1167 Tft.drawString("PIR 1168 sensor #", 80, 130, 3, BLUE); 1169 Tft.drawString("PIR sensor #", 80, 130, 1170 3, BLUE); 1171 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 1172 Tft.drawString("<", 1173 0, 160, 3, GREEN); // back button 1174} 1175//<><><><><><><><><><><><><><><><><><><><><><><><> 1176//<><><><><><><><> 1177 end screen 0121 <><><><><><><><><> 1178//<><><><><><><><><><><><><><><><><><><><><><><><> 1179 1180//<><><><><><><><><><><><><><><><><><><><><><><><> 1181//<><><><><><><><> 1182 begin screen 0221 <><><><><><><><> 1183//<><><><><><><><><><><><><><><><><><><><><><><><> 1184 1185 if(currentScreen == 221){ 1186 // " " 1187 Tft.drawString("SOUND",0,5,4,BLUE); 1188 1189 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 1190 Tft.drawString("Sense 1191 Graves", 80,130, 3, BLUE); 1192 Tft.drawString("Jaw position", 05, 195, 3, 1193 GREEN); 1194 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 1195 Tft.drawString("<", 1196 0, 160, 3, GREEN); // back button 1197} 1198//<><><><><><><><><><><><><><><><><><><><><><><><> 1199//<><><><><><><><> 1200 end screen 0221 <><><><><><><><><> 1201//<><><><><><><><><><><><><><><><><><><><><><><><> 1202 1203//<><><><><><><><><><><><><><><><><><><><><><><><> 1204//<><><><><><><><> 1205 begin screen 0031 <><><><><><><><> 1206//<><><><><><><><><><><><><><><><><><><><><><><><> 1207 1208 if(currentScreen == 31){ 1209 // " " 1210 Tft.drawString("Bluetooth",0,5,4,BLUE); 1211 1212 Tft.drawString("Control",10,50,4,YELLOW); 1213 Tft.drawString("On", 1214 80,130, 3, BLUE); 1215 Tft.drawString("Off", 05, 195, 3, GREEN); 1216 Tft.drawString("Monitor", 1217 10, 260, 3, GREEN); 1218 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1219} 1220//<><><><><><><><><><><><><><><><><><><><><><><><> 1221//<><><><><><><><> 1222 end screen 0031 <><><><><><><><><> 1223//<><><><><><><><><><><><><><><><><><><><><><><><> 1224 1225//<><><><><><><><><><><><><><><><><><><><><><><><> 1226//<><><><><><><><> 1227 begin screen 0002 <><><><><><><><> 1228//<><><><><><><><><><><><><><><><><><><><><><><><> 1229 1230 if(currentScreen == 2){ 1231 // " " 1232 Tft.drawString("Mouth",0,5,4,BLUE); 1233 1234 Tft.drawString("Control",10,50,4,YELLOW); 1235 Tft.drawString("Test 1236 Jaw", 80,130, 3, BLUE); 1237 Tft.drawString("Sensor on/off", 05, 195, 3, 1238 GREEN); 1239 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1240 Tft.drawString("<", 1241 0, 160, 3, GREEN); // back button 1242 } 1243//<><><><><><><><><><><><><><><><><><><><><><><><> 1244//<><><><><><><><> 1245 end screen 0002 <><><><><><><><><> 1246//<><><><><><><><><><><><><><><><><><><><><><><><> 1247 1248 1249//<><><><><><><><><><><><><><><><><><><><><><><><> 1250//<><><><><><><><> 1251 begin screen 0012 <><><><><><><><> 1252//<><><><><><><><><><><><><><><><><><><><><><><><> 1253 1254 if(currentScreen == 12){ 1255 // " " 1256 Tft.drawString("Jaw 1257 Test",0,5,4,BLUE); 1258 Tft.drawString("Operations",10,50,4,YELLOW); 1259 1260 Tft.drawString("Open", 80,130, 3, BLUE); 1261 Tft.drawString("Close", 1262 05, 195, 3, GREEN); 1263 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 1264 1265 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1266} 1267//<><><><><><><><><><><><><><><><><><><><><><><><> 1268//<><><><><><><><> 1269 end screen 0012 <><><><><><><><><> 1270//<><><><><><><><><><><><><><><><><><><><><><><><> 1271 1272 1273//<><><><><><><><><><><><><><><><><><><><><><><><> 1274//<><><><><><><><> 1275 begin screen 0022 <><><><><><><><> 1276//<><><><><><><><><><><><><><><><><><><><><><><><> 1277 1278 if(currentScreen == 22){ 1279 // " " 1280 Tft.drawString("Sound",0,5,4,BLUE); 1281 1282 Tft.drawString("Sensors",10,50,4,YELLOW); 1283 Tft.drawString("Alexa 1284 Sense", 80,130, 3, BLUE); 1285 Tft.drawString("Graves Sense", 05, 195, 3, 1286 GREEN); 1287 Tft.drawString("Monitor", 10, 260, 3, GREEN); 1288 Tft.drawString("<", 1289 0, 160, 3, GREEN); // back button 1290} 1291//<><><><><><><><><><><><><><><><><><><><><><><><> 1292//<><><><><><><><> 1293 end screen 0022 <><><><><><><><><> 1294//<><><><><><><><><><><><><><><><><><><><><><><><> 1295 1296 1297 1298//<><><><><><><><><><><><><><><><><><><><><><><><> 1299//<><><><><><><><> 1300 begin screen 0122 <><><><><><><><> 1301//<><><><><><><><><><><><><><><><><><><><><><><><> 1302 1303 if(currentScreen == 122){ 1304 // " " 1305 Tft.drawString("Alexa 1306 Sense",0,5,4,BLUE); 1307 Tft.drawString("Operations",10,50,4,YELLOW); 1308 1309 Tft.drawString("On", 120, 130, 3, GREEN); 1310 Tft.drawString("Off", 1311 115, 195, 3, RED); 1312 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1313 1314 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1315} 1316//<><><><><><><><><><><><><><><><><><><><><><><><> 1317//<><><><><><><><> 1318 end screen 0122 <><><><><><><><><> 1319//<><><><><><><><><><><><><><><><><><><><><><><><> 1320 1321//<><><><><><><><><><><><><><><><><><><><><><><><> 1322//<><><><><><><><> 1323 begin screen 0222 <><><><><><><><> 1324//<><><><><><><><><><><><><><><><><><><><><><><><> 1325 1326 if(currentScreen == 222){ 1327 // " " 1328 Tft.drawString("Graves 1329 Sense",0,5,4,BLUE); 1330 Tft.drawString("Operations",10,50,4,YELLOW); 1331 1332 Tft.drawString("On", 120, 130, 3, GREEN); 1333 Tft.drawString("Off", 1334 115, 195, 3, RED); 1335 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1336 1337 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1338} 1339//<><><><><><><><><><><><><><><><><><><><><><><><> 1340//<><><><><><><><> 1341 end screen 0222 <><><><><><><><><> 1342//<><><><><><><><><><><><><><><><><><><><><><><><> 1343 1344//<><><><><><><><><><><><><><><><><><><><><><><><> 1345//<><><><><><><><> 1346 begin screen 0032 <><><><><><><><> 1347//<><><><><><><><><><><><><><><><><><><><><><><><> 1348 1349 if(currentScreen == 32){ 1350 // " " 1351 Tft.drawString("Sound 1352 Sense",0,5,4,BLUE); 1353 Tft.drawString("Monitors",10,50,4,YELLOW); 1354 Tft.drawString("Alexa", 1355 80,130, 3, BLUE); 1356 Tft.drawString("Graves", 05, 195, 3, GREEN); 1357 Tft.drawString("<", 1358 0, 160, 3, GREEN); // back button 1359} 1360//<><><><><><><><><><><><><><><><><><><><><><><><> 1361//<><><><><><><><> 1362 end screen 0032 <><><><><><><><><> 1363//<><><><><><><><><><><><><><><><><><><><><><><><> 1364 1365//<><><><><><><><><><><><><><><><><><><><><><><><> 1366//<><><><><><><><> 1367 begin screen 0003 <><><><><><><><> 1368//<><><><><><><><><><><><><><><><><><><><><><><><> 1369 1370 if(currentScreen == 3){ 1371 // " " 1372 Tft.drawString("Head 1373 Control",0,5,4,BLUE); 1374 Tft.drawString("Operations",10,50,4,YELLOW); 1375 1376 Tft.drawString("PIR Array", 80,130, 3, BLUE); 1377 Tft.drawString("Motor 1378 On/Off", 05, 195, 3, GREEN); 1379 Tft.drawString("Manual Point", 10, 260, 1380 3, GREEN); 1381 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1382} 1383//<><><><><><><><><><><><><><><><><><><><><><><><> 1384//<><><><><><><><> 1385 end screen 0003 <><><><><><><><><> 1386//<><><><><><><><><><><><><><><><><><><><><><><><> 1387 1388//<><><><><><><><><><><><><><><><><><><><><><><><> 1389//<><><><><><><><> 1390 begin screen 0013 <><><><><><><><> 1391//<><><><><><><><><><><><><><><><><><><><><><><><> 1392 1393 if(currentScreen == 13){ 1394 // " " 1395 Tft.drawString("PIR 1396 Control",0,5,4,BLUE); 1397 Tft.drawString("Operations",10,50,4,YELLOW); 1398 1399 Tft.drawString("On", 80,130, 3, BLUE); 1400 Tft.drawString("Off", 1401 05, 195, 3, GREEN); 1402 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 1403 1404 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1405} 1406//<><><><><><><><><><><><><><><><><><><><><><><><> 1407//<><><><><><><><> 1408 end screen 0013 <><><><><><><><><> 1409//<><><><><><><><><><><><><><><><><><><><><><><><> 1410 1411//<><><><><><><><><><><><><><><><><><><><><><><><> 1412//<><><><><><><><> 1413 begin screen 0023 <><><><><><><><> 1414//<><><><><><><><><><><><><><><><><><><><><><><><> 1415 1416 if(currentScreen == 23){ 1417 // " " 1418 Tft.drawString("Graves 1419 Head",0,5,3,BLUE); 1420 Tft.drawString("Operations",10,50,3,YELLOW); 1421 1422 Tft.drawString("On", 120, 130, 3, GREEN); 1423 Tft.drawString("Off", 1424 115, 195, 3, RED); 1425// Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1426 1427 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1428} 1429//<><><><><><><><><><><><><><><><><><><><><><><><> 1430//<><><><><><><><> 1431 end screen 0023 <><><><><><><><><> 1432//<><><><><><><><><><><><><><><><><><><><><><><><> 1433 1434 1435//<><><><><><><><><><><><><><><><><><><><><><><><> 1436//<><><><><><><><> 1437 begin screen 0422 <><><><><><><><> 1438//<><><><><><><><><><><><><><><><><><><><><><><><> 1439 1440 if(currentScreen == 422){ 1441 // " " 1442 Tft.drawString("Command 1443 Sent",0,5,3,BLUE); 1444 Tft.drawString("Press Back to",0,55,3,YELLOW); 1445 1446 Tft.drawString("Contiue", 50,105, 3, BLUE); 1447 Tft.drawString("<", 1448 0, 160, 3, GREEN); // back button 1449} 1450//<><><><><><><><><><><><><><><><><><><><><><><><> 1451//<><><><><><><><> 1452 end screen 0422 <><><><><><><><><> 1453//<><><><><><><><><><><><><><><><><><><><><><><><> 1454 1455 1456////<><><><><><><><><><><><><><><><><><><><><><><><> 1457////<><><><><><><><> 1458 begin screen lost <><><><><><><><> 1459////<><><><><><><><><><><><><><><><><><><><><><><><> 1460// 1461 else if(currentScreen){ 1462// // " " 1463// 1464 Tft.drawString("Screen not",0,5,3,BLUE); 1465// Tft.drawString("found. 1466 Please",40,50,3,YELLOW); 1467// Tft.drawString("use the back", 80,130, 3, 1468 BLUE); 1469// Tft.drawString("button to", 05, 195, 3, GREEN); 1470// Tft.drawString("return 1471 to fun", 10, 260, 3, GREEN); 1472// Tft.drawString("<", 0, 160, 3, GREEN); 1473 // back button 1474//} 1475////<><><><><><><><><><><><><><><><><><><><><><><><> 1476////<><><><><><><><> 1477 end screen lost <><><><><><><><><> 1478////<><><><><><><><><><><><><><><><><><><><><><><><> 1479 1480}// 1481 callScreen 1482//-------------------------- end callScreen function ------------------------- 1483//-------------------------- 1484 end callScreen function ------------------------- 1485//-------------------------- 1486 end callScreen function ------------------------- 1487//-------------------------- 1488 end callScreen function ------------------------- 1489//-------------------------- 1490 end callScreen function ------------------------- 1491//-------------------------- 1492 end callScreen function ------------------------- 1493//-------------------------- 1494 end callScreen function ------------------------- 1495//-------------------------- 1496 end callScreen function ------------------------- 1497//-------------------------- 1498 end callScreen function ------------------------- 1499//-------------------------- 1500 end callScreen function ------------------------- 1501//-------------------------- 1502 end callScreen function ------------------------- 1503//-------------------------- 1504 end callScreen function ------------------------- 1505//-------------------------- 1506 end callScreen function ------------------------- 1507 1508 1509//**************************************************************************************************** 1510//**************************************************************************************************** 1511 1512 1513 1514 1515 1516 1517 1518//**************************************************************************************************** 1519//**************************************************************************************************** 1520 1521// 1522 fin
draft 2
c_cpp
initial screen creation and menu build some tft tracking and display
1/* 2last edit sun oct 7 2018 3 4Graves multi arduino build 10/2018 5Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 6two arduino uno's 7slave1 arduino uno to sense sound from graves and echo dot to control mouth 8slave2 arduino uno to control passive sensor array and head servo 9 10sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 11 12 analogue pin speaker + 13 \ / (red from speaker) 14 \ / 15 \ / 16 *--------[=]-----------*---------[=]----------* 17 | resistor \ resistor | 18 | \ | 19 |(red with white) \ |to arduino ground (black with white) 20to arduino 5v+ speaker - 21 (black from speaker) 22 23*/ 24 25//#include <TFT.h> 26//#include <Servo.h> 27//#include <stdint.h> 28//#include <SD.h> 29#include <TFTv2.h> 30#include <SPI.h> 31#include <SeeedTouchScreen.h> 32 33//const int PIN_SD_CS = 4; // pin of sd card 34 35TouchScreen ts = TouchScreen(XP, YP, XM, YM); 36 37 38//********************************************************* 39//********************************************************* 40 41// begin void setup 42// begin void setup 43// begin void setup 44// begin void setup 45// begin void setup 46// begin void setup 47// begin void setup 48// begin void setup 49// begin void setup 50// begin void setup 51// begin void setup 52 53void setup() { 54 // need timer to track screen timeout 55 // set screen to on and let timer run to turn off 56 Tft.TFTinit(); // init TFT library 57 TFT_BL_ON; // turn on the background light 58 59screenMaster(); //calls function to draw title and menu items 60 61} //void setup() 62 63// end void setup 64// end void setup 65// end void setup 66// end void setup 67// end void setup 68// end void setup 69// end void setup 70// end void setup 71 72//********************************************************* 73//********************************************************* 74 75// begin void loop 76// begin void loop 77// begin void loop 78// begin void loop 79// begin void loop 80// begin void loop 81// begin void loop 82// begin void loop 83 84void loop() { 85 86 87//tftDetect(); // gather information from touch screen touches 88 89tftDisplay(); // display x y coordinates on tft display 90 91} //void loop() 92 93// end of void loop 94// end of void loop 95// end of void loop 96// end of void loop 97// end of void loop 98// end of void loop 99// end of void loop 100// end of void loop 101// end of void loop 102// end of void loop 103// end of void loop 104// end of void loop 105// end of void loop 106// end of void loop 107 108///////////////////////////////////////////////////////////////////////////////////////////////////////// 109////////////////////////////////////////// /////////////////////////////////////////////////// 110///////////////////////////////////////// functions /////////////////////////////////////////////////// 111//////////////////////////////////////// /////////////////////////////////////////////////// 112///////////////////////////////////////////////////////////////////////////////////////////////////////// 113 114//**************************************************************************************************** 115//**************************************************************************************************** 116//--------------------------begin TFT input code---------------------------------- 117void tftDetect(){ 118 // a point object holds x y and z coordinates 119 Point p = ts.getPoint(); 120 if(100<p.z && p.z<460){ // max and min z variable later? acts as debounce 121 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 122 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 123 }//if 124}//void tftDetect 125//--------------------------end TFT intput code---------------------------------- 126//**************************************************************************************************** 127//**************************************************************************************************** 128 129//--------------------------begin arduino master data fetch calls---------------------------------- 130// call slave1 arduino for data 131// call slave2 arduino for data 132//--------------------------end arduino master data fetch calls------------------------------------ 133 134//**************************************************************************************************** 135//**************************************************************************************************** 136 137//--------------------------begin TFT output code---------------------------------- 138void tftDisplay(){ 139 Point p = ts.getPoint(); 140 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 141 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 142// p.z = map(p.z, 0, 600, 100, 0); 143 144 if(100<p.z && p.z<460){ // max and min z variable later? acts as debounce 145 Tft.fillRectangle(0, 160, 60, 30, BLACK); 146 Tft.drawNumber((p.x), 0, 160, 3, GREEN); 147 Tft.fillRectangle(180, 160, 60, 30, BLACK); 148 Tft.drawNumber((p.y), 180, 160, 3, GREEN); 149 }//if 150}// void tftDisplay 151//--------------------------end TFT output code------------------------------------ 152 153//**************************************************************************************************** 154//**************************************************************************************************** 155 156//-------------------------- begin slave1 data fetch function -------------------------- 157//-------------------------- end slave1 data fetch function -------------------------- 158 159//**************************************************************************************************** 160//**************************************************************************************************** 161 162//-------------------------- begin slave2 data fetch function -------------------------- 163//-------------------------- end slave2 data fetch function ------------------------- 164 165//**************************************************************************************************** 166//**************************************************************************************************** 167 168 169//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 170//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 171//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 172//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 173//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 174/* 175background screen file names on sd card 176pipboybg.bmp 177pipboylocked.bmp 178tft2buttons.bmp 179tft3buttons.bmp 180*/ 181//**************************************************************************************************** 182//**************************************************************************************************** 183 184//--------------------------- Primary screen maps -------------------------------- 185/* 186 text size 3 can fit 13 characters 187 188screen 1 A)master 189screen 2 a)settings 190screen 2 -brightness 191screen 2 -contrast 192screen 2 -screen lock time out 193screen 3 b)sensor monitors 194screen 3 -pir 195screen 4 *report pir detection 196screen 4 *report head servo position 197screen 3 -sound 198screen 5 *sense alexa sound 199screen 5 *sense graves sound 200screen 5 *report mouth servo position 201screen 5 *adjust sensitivity? 202screen 3 c)bluetooth 203screen 6 -on 204screen 6 -off 205screen 6 -monitor 206 207screen 7 B)slave1 mouth servo 208screen 7 a)test button 209screen 8 -open 210screen 8 -close 211screen 8 -push button chicken switch 212screen 7 b)sound sensors on/off 213screen 9 -alexa sense 214screen 10 *on 215screen 10 *off 216screen 10 *monitor sensor 217screen 9 -graves sense 218screen 11 *on 219screen 11 *off 220screen 11 *monitor sensors 221screen 7 c)sound sensor status 222screen 12 -alexa 223screen 12 -graves 224 225screen 13 C)slave2 head servo 226screen 14 a)pir on/off 227screen 15 -on 228screen 15 -off 229screen 14 b)manual point 230screen 16 -slider 231*/ 232 233//<><><><><><><><><><><><><><><><><><><><><><><><> 234//<><><><><><><><> begin screen master <><><><><><><><> 235//<><><><><><><><><><><><><><><><><><><><><><><><> 236void screenMaster(){ 237 // " " 238 Tft.drawString("Undertaker",0,5,4,GREEN); 239 Tft.drawString("Interface",10,50,4,GREEN); 240 Tft.drawString("Home", 80,130, 3, GREEN); 241 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 242 Tft.drawString("Head Control", 10, 260, 3, GREEN); 243} 244//<><><><><><><><><><><><><><><><><><><><><><><><> 245//<><><><><><><><> end screen master <><><><><><><><><> 246//<><><><><><><><><><><><><><><><><><><><><><><><> 247 248//<><><><><><><><><><><><><><><><><><><><><><><><> 249//<><><><><><><><> begin screen 1 <><><><><><><><> 250//<><><><><><><><><><><><><><><><><><><><><><><><> 251 252//<><><><><><><><><><><><><><><><><><><><><><><><> 253//<><><><><><><><> end screen 1 <><><><><><><><><> 254//<><><><><><><><><><><><><><><><><><><><><><><><> 255 256 257//<><><><><><><><><><><><><><><><><><><><><><><><> 258//<><><><><><><><> begin screen 2 <><><><><><><><> 259//<><><><><><><><><><><><><><><><><><><><><><><><> 260 261 262//<><><><><><><><><><><><><><><><><><><><><><><><> 263//<><><><><><><><> end screen 2 <><><><><><><><><> 264//<><><><><><><><><><><><><><><><><><><><><><><><> 265 266 267 268//<><><><><><><><><><><><><><><><><><><><><><><><> 269//<><><><><><><><> begin screen 3 <><><><><><><><> 270//<><><><><><><><><><><><><><><><><><><><><><><><> 271 272 273//<><><><><><><><><><><><><><><><><><><><><><><><> 274//<><><><><><><><> end screen 3 <><><><><><><><><> 275//<><><><><><><><><><><><><><><><><><><><><><><><> 276 277 278//<><><><><><><><><><><><><><><><><><><><><><><><> 279//<><><><><><><><> begin screen 4 <><><><><><><><> 280//<><><><><><><><><><><><><><><><><><><><><><><><> 281 282 283//<><><><><><><><><><><><><><><><><><><><><><><><> 284//<><><><><><><><> end screen 4 <><><><><><><><><> 285//<><><><><><><><><><><><><><><><><><><><><><><><> 286 287 288//<><><><><><><><><><><><><><><><><><><><><><><><> 289//<><><><><><><><> begin screen 5 <><><><><><><><> 290//<><><><><><><><><><><><><><><><><><><><><><><><> 291 292 293//<><><><><><><><><><><><><><><><><><><><><><><><> 294//<><><><><><><><> end screen 5 <><><><><><><><><> 295//<><><><><><><><><><><><><><><><><><><><><><><><> 296 297 298 299//<><><><><><><><><><><><><><><><><><><><><><><><> 300//<><><><><><><><> begin screen 6 <><><><><><><><> 301//<><><><><><><><><><><><><><><><><><><><><><><><> 302 303 304//<><><><><><><><><><><><><><><><><><><><><><><><> 305//<><><><><><><><> end screen 6 <><><><><><><><><> 306//<><><><><><><><><><><><><><><><><><><><><><><><> 307 308 309//<><><><><><><><><><><><><><><><><><><><><><><><> 310//<><><><><><><><> begin screen 7 <><><><><><><><> 311//<><><><><><><><><><><><><><><><><><><><><><><><> 312 313 314//<><><><><><><><><><><><><><><><><><><><><><><><> 315//<><><><><><><><> end screen 7 <><><><><><><><><> 316//<><><><><><><><><><><><><><><><><><><><><><><><> 317 318 319//<><><><><><><><><><><><><><><><><><><><><><><><> 320//<><><><><><><><> begin screen 8 <><><><><><><><> 321//<><><><><><><><><><><><><><><><><><><><><><><><> 322 323 324//<><><><><><><><><><><><><><><><><><><><><><><><> 325//<><><><><><><><> end screen 8 <><><><><><><><><> 326//<><><><><><><><><><><><><><><><><><><><><><><><> 327 328 329 330//<><><><><><><><><><><><><><><><><><><><><><><><> 331//<><><><><><><><> begin screen 9 <><><><><><><><> 332//<><><><><><><><><><><><><><><><><><><><><><><><> 333 334 335//<><><><><><><><><><><><><><><><><><><><><><><><> 336//<><><><><><><><> end screen 9 <><><><><><><><><> 337//<><><><><><><><><><><><><><><><><><><><><><><><> 338 339 340//<><><><><><><><><><><><><><><><><><><><><><><><> 341//<><><><><><><><> begin screen 10 <><><><><><><><> 342//<><><><><><><><><><><><><><><><><><><><><><><><> 343 344 345//<><><><><><><><><><><><><><><><><><><><><><><><> 346//<><><><><><><><> end screen 10 <><><><><><><><><> 347//<><><><><><><><><><><><><><><><><><><><><><><><> 348 349 350//<><><><><><><><><><><><><><><><><><><><><><><><> 351//<><><><><><><><> begin screen 11 <><><><><><><><> 352//<><><><><><><><><><><><><><><><><><><><><><><><> 353 354 355//<><><><><><><><><><><><><><><><><><><><><><><><> 356//<><><><><><><><> end screen 11 <><><><><><><><><> 357//<><><><><><><><><><><><><><><><><><><><><><><><> 358 359 360 361//<><><><><><><><><><><><><><><><><><><><><><><><> 362//<><><><><><><><> begin screen 12 <><><><><><><><> 363//<><><><><><><><><><><><><><><><><><><><><><><><> 364 365 366//<><><><><><><><><><><><><><><><><><><><><><><><> 367//<><><><><><><><> end screen 12 <><><><><><><><><> 368//<><><><><><><><><><><><><><><><><><><><><><><><> 369 370 371 372//**************************************************************************************************** 373//**************************************************************************************************** 374 375 376 377 378 379 380 381//**************************************************************************************************** 382//**************************************************************************************************** 383 384// fin
25102018 night mega code PAGES UPDATED!!!
c_cpp
Man, that was tough! All pages updated and coupled to button groups. button groups updated to accommodate backlight timer adjustment
1/* 225102018 3 4gravesmegamaster 5 6graves project 7arduino 8 MEGA 2650 9Master 10coded from scratch by wylie jones 11wyliejones@gmail.com 12 13Graves 14 multi arduino build 10/2018 15Arduino mega 2560 with 240/320 tft and micro sd card 16 (for storing screen backgrounds) 17two arduino uno's 18slave1 arduino uno to sense 19 sound from graves and echo dot to control mouth 20slave2 arduino uno to control 21 passive sensor array and head servo 22 23sound is sensed with a simple DC bias 24 circuit to capture line level input to be used as a digital signal 25 26 analogue 27 pin speaker + 28 \(yellow signal / 29 (red from speaker) 30 10k Ohm \ wire) / 31 resistor 32 \ / 33 *--------/\\/\\/---------*---------/\\/\\/--------* 34 35 | \ 10k Ohm | 36 | \\ 37 resistor | 38 |(red with white) \ |to arduino 39 ground (black with white) 40to arduino 5v+ -)|- 41 \\ 42 100uF 16v 43 \ capacitor 44 \\ 45 46 \\ 47 speaker - 48 (black 49 from speaker) 50 51*/ 52//end notes 53//end notes 54//end notes 55//end notes 56//end 57 notes 58//end notes 59 60 61//********************************************************* 62//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 63//********************************************************* 64 65 66//begin 67 declarations 68//begin declarations 69//begin declarations 70//begin declarations 71//begin 72 declarations 73//begin declarations 74//begin declarations 75 76//#include <TFT.h> 77//#include 78 <Servo.h> 79//#include <stdint.h> 80//#include <SD.h> 81#include <TFTv2.h> 82#include 83 <SPI.h> 84#include <SeeedTouchScreen.h> 85//#include <Wire.h> 86 87//const 88 int PIN_SD_CS = 4; // pin of sd card 89 90TouchScreen ts 91 = TouchScreen(XP, YP, XM, YM); 92int zMax; // maximum pressure to detect 93int 94 zMin; // minimum pressure to detect 95 96int buttonPressed; // stores which button 97 was pressed 98unsigned long newButtonTime; // debounce 99unsigned long oldButtonTime; 100 // debounce 101unsigned long buttonTimeDifference; // debounce 102unsigned long 103 debounceTime; // debounce 104int buttonGroup; // sets kinds of buttons on screen 105 106int 107 currentScreen; // identifies current screen by adding x y and z 108int x; // for 109 ones 110int y; // for tens 111int z; // for hundreds 112 113unsigned long backlightTimer; 114 // for backlight timeout 115int backLightState; // status of backlight 1 for on 116 and 0 for off 117unsigned long backlightTimeDifference; 118unsigned long newBacklightTime; 119unsigned 120 long oldBacklightTime; 121 122char incomingMouthByte; 123char outgoingMouthByte; 124int 125 mouthOnOffNew; 126int mouthOnOffOld; 127int mouthOnOffDifference; 128int mouthOnOffAdjusted; 129 // value adjusted by 48 for ascii 130 131char incomingHeadByte; 132char outgoingHeadByte; 133int 134 headOnOffNew; 135int headOnOffOld; 136int headOnOffDifference; 137int headOnOffAdjusted; 138 // value adjusted by 48 for ascii 139 140//end declarations 141//end declarations 142//end 143 declarations 144//end declarations 145//end declarations 146//end declarations 147//end 148 declarations 149//end declarations 150//end declarations 151 152//********************************************************* 153//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 154//********************************************************* 155 156// 157 begin void setup 158// begin void setup 159// begin void setup 160// begin void 161 setup 162// begin void setup 163// begin void setup 164// begin void setup 165// 166 begin void setup 167// begin void setup 168// begin void setup 169// begin void 170 setup 171void setup() { 172Serial.begin(9600); 173Serial1.begin(9600); 174Serial2.begin(9600); 175 176 oldButtonTime = millis(); 177 newButtonTime = millis(); 178 Tft.TFTinit(); // 179 init TFT library 180 TFT_BL_ON; // turn on the background light 181 backLightState 182 = 1; 183 x = 0; 184 y = 0; 185 z = 0; 186 buttonPressed = 4; 187 buttonGroup 188 = 0; 189 190 incomingHeadByte = 1; 191 outgoingHeadByte = 1; // for a bit more 192 talkative serial data 193 headOnOffNew = 1; // stores head state from serial connection 194 195 headOnOffOld = 1; // stores head state from serial connection 196 197 198 incomingMouthByte 199 = 0; 200 outgoingMouthByte = 0; // for a bit more talkative serial data 201 mouthOnOffNew 202 = 1; // stores mouth state from serial connection 203 mouthOnOffOld = 1; // stores 204 mouth state from serial connection 205 206 207 //////////////////////////////// 208 209 //// manually set variables //// 210 //////////////////////////////// 211// 212 \\/ \\/ \\/ \\/ \\/ \\/ 213 214 debounceTime 215 = 1000; // button debounce in milliseconds 216 zMax = 460; // maximum pressure 217 to detect 218 zMin = 100; // minimum pressure to detect 219 220 backlightTimer 221 = 15000; // 5000 = 5 seconds for backlight timeout 222 223// 224 /\ /\ /\ /\ /\ /\\ 225 //////////////////////////////// 226 227 //// manually set variables //// 228 //////////////////////////////// 229 230 231 232 currentScreen = 0; 233 callScreen(); 234 235} //void setup() 236// end void 237 setup 238// end void setup 239// end void setup 240// end void setup 241// end void 242 setup 243// end void setup 244// end void setup 245// end void setup 246 247//********************************************************* 248//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 249//********************************************************* 250 251// 252 begin void loop 253// begin void loop 254// begin void loop 255// begin void loop 256// 257 begin void loop 258// begin void loop 259// begin void loop 260// begin void loop 261// 262 begin void loop 263// begin void loop 264// begin void loop 265// begin void loop 266// 267 begin void loop 268// begin void loop 269 270void loop() { 271 272 tftBacklightTimeout(); 273 // check time and turn off backlight 274 275 if(buttonGroup == 0){ // most regular 276 pages 277 tftButtonGroup0(); // gather information from touch screen touches 278 279 buttonTimeDifference = newButtonTime - oldButtonTime; 280 if(debounceTime 281 < buttonTimeDifference){ 282 whatScreen(); 283 callScreen(); 284 oldButtonTime 285 = newButtonTime; 286 showStuff(); // serial prints 287 tftDisplay(); // 288 display x y coordinates on tft display 289 } 290 } 291 if(buttonGroup == 1){ 292 // on off buttons 293 tftButtonGroup1(); // gather information from touch screen 294 touches 295 buttonTimeDifference = newButtonTime - oldButtonTime; 296 if(debounceTime 297 < buttonTimeDifference){ 298 whatScreen(); 299 callScreen(); 300 oldButtonTime 301 = newButtonTime; 302 showStuff(); // serial prints 303 tftDisplay(); // 304 display x y coordinates on tft display 305 mouthUnoTxRx(); 306 } 307 } 308 309 if(buttonGroup == 2){ // head buttons 310 tftButtonGroup2(); // gather information 311 from touch screen touches 312 buttonTimeDifference = newButtonTime - oldButtonTime; 313 314 if(debounceTime < buttonTimeDifference){ 315 whatScreen(); 316 callScreen(); 317 318 oldButtonTime = newButtonTime; 319 showStuff(); // serial prints 320 321 tftDisplay(); // display x y coordinates on tft display 322 headUnoTxRx(); 323 324 } 325 } 326 if(buttonGroup == 3){ // head buttons 327 tftButtonGroup3(); 328 // gather information from touch screen touches 329 buttonTimeDifference = newButtonTime 330 - oldButtonTime; 331 if(debounceTime < buttonTimeDifference){ 332 whatScreen(); 333 334 callScreen(); 335 oldButtonTime = newButtonTime; 336 showStuff(); 337 // serial prints 338 tftDisplay(); // display x y coordinates on tft display 339 340 } 341 } 342 343 344} //void loop() 345 346// end of void loop 347// end of 348 void loop 349// end of void loop 350// end of void loop 351// end of void loop 352// 353 end of void loop 354// end of void loop 355// end of void loop 356// end of void 357 loop 358// end of void loop 359// end of void loop 360// end of void loop 361// 362 end of void loop 363// end of void loop 364// end of void loop 365 366//**************************************************************************************************** 367//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 368//**************************************************************************************************** 369///////////////////////////////////////////////////////////////////////////////////////////////////////// 370///////////////////////////////////////// 371 functions /////////////////////////////////////////////////// 372///////////////////////////////////////////////////////////////////////////////////////////////////////// 373//**************************************************************************************************** 374//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 375//**************************************************************************************************** 376 377//--------------------------begin 378 tftBacklightTimeout---------------------------------- 379void tftBacklightTimeout(){ 380 381 newBacklightTime = millis(); 382 if(backLightState = 0){ 383 backlightTimeDifference 384 = newBacklightTime - oldBacklightTime; 385 if(backlightTimer > backlightTimeDifference){ 386 387 backlightTimeDifference = newBacklightTime - oldBacklightTime; 388 TFT_BL_ON; 389 // turn on the background light 390 backLightState = 1; 391 oldBacklightTime 392 = millis(); 393 } 394 } 395 if(backLightState = 1){ 396 backlightTimeDifference 397 = newBacklightTime - oldBacklightTime; 398 if(backlightTimer < backlightTimeDifference){ 399 400 backlightTimeDifference = newBacklightTime - oldBacklightTime; 401 TFT_BL_OFF; 402 // turn off the background light 403 backLightState = 0; 404 oldBacklightTime 405 = millis(); 406 } 407 } 408} 409//--------------------------end tftBacklightTimeout---------------------------------- 410 411//**************************************************************************************************** 412//**************************************************************************************************** 413 414//--------------------------begin 415 tftButtonGroup0---------------------------------- 416//--------------------------begin 417 tftButtonGroup0---------------------------------- 418//--------------------------begin 419 tftButtonGroup0---------------------------------- 420//--------------------------begin 421 tftButtonGroup0---------------------------------- 422int tftButtonGroup0(){ 423 424 Point p = ts.getPoint(); 425 if(zMin<p.z && p.z<zMax){ 426 TFT_BL_ON; // 427 turn on the background light 428 backLightState = 1; 429 oldBacklightTime 430 = millis(); 431 newButtonTime = millis(); 432 p.x = map(p.x, TS_MINX, TS_MAXX, 433 0, 240); 434 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 435//Button 1 436 if(75<p.x 437 && p.x<140){ 438 if(100<p.y && p.y<164){ 439 buttonPressed = 1; 440 441 } 442//Button 2 443 if(164<p.y && p.y<240){ 444 buttonPressed 445 = 2; 446 } 447//Button 3 448 if(240<p.y && p.y<310){ 449 buttonPressed 450 = 3; 451 } 452 } 453 } 454//Button 4 455 if(10<p.x && p.x<75){ 456 457 if(100<p.y && p.y<240){ 458 buttonPressed = 4; 459 } 460 461 } 462}//void tftButtonGroup0 463//--------------------------end tftButtonGroup0 464 code---------------------------------- 465//--------------------------end tftButtonGroup0 466 code---------------------------------- 467//--------------------------end tftButtonGroup0 468 code---------------------------------- 469//--------------------------end tftButtonGroup0 470 code---------------------------------- 471//--------------------------end tftButtonGroup0 472 code---------------------------------- 473//**************************************************************************************************** 474//**************************************************************************************************** 475 476//--------------------------begin 477 tftButtonGroup1---------------------------------- 478//--------------------------begin 479 tftButtonGroup1---------------------------------- 480//--------------------------begin 481 tftButtonGroup1---------------------------------- 482//--------------------------begin 483 tftButtonGroup1---------------------------------- 484int tftButtonGroup1(){ // 485 for mouth 486buttonPressed = 0; 487 Point p = ts.getPoint(); 488 if(zMin<p.z && 489 p.z<zMax){ 490 TFT_BL_ON; // turn on the background light 491 backLightState 492 = 1; 493 oldBacklightTime = millis(); 494 newButtonTime = millis(); 495 496 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 497 p.y = map(p.y, TS_MINY, TS_MAXY, 498 0, 320); 499//Button 1 500 if(75<p.x && p.x<140){ 501 if(100<p.y && p.y<164){ 502 503 mouthOnOffNew = 1; // on 504 Serial.print("mouthOnOffNew set to 505 "); 506 Serial.println(mouthOnOffNew); 507 } 508//Button 2 509 510 if(164<p.y && p.y<240){ 511 mouthOnOffNew = 2; // off 512 Serial.print("mouthOnOffNew 513 set to "); 514 Serial.println(mouthOnOffNew); 515 } 516//Button 3 517// 518 if(240<p.y && p.y<310){ 519// mouthOnOffNew = 3; // off 520// Serial.print("mouthOnOffNew 521 set to "); 522// Serial.println(mouthOnOffNew); 523// } 524 } 525 526 } 527//Button 4 528 if(10<p.x && p.x<75){ 529 if(100<p.y && 530 p.y<240){ 531 buttonPressed = 4; 532 buttonGroup = 0; 533 } 534 535 } 536}//void tftButtonGroup1 537//--------------------------end tftButtonGroup1 538 code---------------------------------- 539//--------------------------end tftButtonGroup1 540 code---------------------------------- 541//--------------------------end tftButtonGroup1 542 code---------------------------------- 543//--------------------------end tftButtonGroup1 544 code---------------------------------- 545//--------------------------end tftButtonGroup1 546 code---------------------------------- 547//**************************************************************************************************** 548//**************************************************************************************************** 549 550//--------------------------begin 551 tftButtonGroup2---------------------------------- 552//--------------------------begin 553 tftButtonGroup2---------------------------------- 554//--------------------------begin 555 tftButtonGroup2---------------------------------- 556//--------------------------begin 557 tftButtonGroup2---------------------------------- 558int tftButtonGroup2(){ // 559 for mouth 560buttonPressed = 0; 561 Point p = ts.getPoint(); 562 if(zMin<p.z && 563 p.z<zMax){ 564 TFT_BL_ON; // turn on the background light 565 backLightState 566 = 1; 567 oldBacklightTime = millis(); 568 newButtonTime = millis(); 569 570 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 571 p.y = map(p.y, TS_MINY, TS_MAXY, 572 0, 320); 573//Button 1 574 if(75<p.x && p.x<140){ 575 if(100<p.y && p.y<164){ 576 577 headOnOffNew = 1; // on 578 Serial.print("headOnOffNew set to "); 579 580 Serial.println(headOnOffNew); 581 } 582//Button 2 583 if(164<p.y 584 && p.y<240){ 585 headOnOffNew = 2; // off 586 Serial.print("headOnOffNew 587 set to "); 588 Serial.println(headOnOffNew); 589 } 590//Button 3 591// 592 if(240<p.y && p.y<310){ 593// buttonPressed = 3; 594// } 595 596 } 597 } 598//Button 4 599 if(10<p.x && p.x<75){ 600 if(100<p.y 601 && p.y<240){ 602 buttonPressed = 4; 603 buttonGroup = 0; 604 } 605 606 } 607}//void tftButtonGroup2 608//--------------------------end tftButtonGroup2 609 code---------------------------------- 610//--------------------------end tftButtonGroup2 611 code---------------------------------- 612//--------------------------end tftButtonGroup2 613 code---------------------------------- 614//--------------------------end tftButtonGroup2 615 code---------------------------------- 616//--------------------------end tftButtonGroup2 617 code---------------------------------- 618//**************************************************************************************************** 619//**************************************************************************************************** 620//--------------------------begin 621 tftButtonGroup3---------------------------------- 622//--------------------------begin 623 tftButtonGroup3---------------------------------- 624//--------------------------begin 625 tftButtonGroup3---------------------------------- 626//--------------------------begin 627 tftButtonGroup3---------------------------------- 628int tftButtonGroup3(){ // 629 for tft backlight 630buttonPressed = 0; 631 Point p = ts.getPoint(); 632 if(zMin<p.z 633 && p.z<zMax){ 634 TFT_BL_ON; // turn on the background light 635 backLightState 636 = 1; 637 oldBacklightTime = millis(); 638 newButtonTime = millis(); 639 640 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 641 p.y = map(p.y, TS_MINY, TS_MAXY, 642 0, 320); 643 if(75<p.x && p.x<140){ 644//Button 1 645 if(100<p.y && p.y<164){ 646 647 backlightTimer = 120000; 648 } 649//Button 2 650 if(164<p.y 651 && p.y<240){ 652 backlightTimer = 15000; 653 } 654//Button 3 655 656 if(240<p.y && p.y<310){ 657 buttonPressed = 3; 658 backlightTimer 659 = 5000; 660 } 661 } 662 } 663//Button 4 664 if(10<p.x && p.x<75){ 665 666 if(100<p.y && p.y<240){ 667 buttonPressed = 4; 668 buttonGroup 669 = 0; 670 } 671 } 672}//void tftButtonGroup3 673//--------------------------end 674 tftButtonGroup3 code---------------------------------- 675//--------------------------end 676 tftButtonGroup3 code---------------------------------- 677//--------------------------end 678 tftButtonGroup3 code---------------------------------- 679//--------------------------end 680 tftButtonGroup3 code---------------------------------- 681//--------------------------end 682 tftButtonGroup3 code---------------------------------- 683//**************************************************************************************************** 684//**************************************************************************************************** 685 686//--------------------------begin 687 mouthUnoTxRx---------------------------------- 688 689void mouthUnoTxRx(){ 690 if(mouthOnOffNew 691 != mouthOnOffOld){ 692 Serial.println("starting txrx"); 693 if(mouthOnOffNew 694 == 1){ 695 Serial.println("Starting tx"); 696 Serial1.flush(); 697 Serial1.write('1'); 698 699 mouthOnOffOld = 1; 700//begin rx 701 Serial.println("Starting rx"); 702 703 704 delay(10); // tweak delay to accomodate uno 705 706 // use a serial 707 available after flush funtion while or for loop or interrrupt or somethin 708 incomingMouthByte 709 = Serial1.read(); 710 Serial1.flush(); 711 mouthOnOffAdjusted = incomingMouthByte; 712 713 Serial.print("mouthOnOffAdjusted should be 1: "); 714 Serial.println(mouthOnOffAdjusted); 715 716 } 717 if(mouthOnOffNew == 2){ 718 Serial.println("Starting tx"); 719 720 Serial1.flush(); 721 Serial1.write('2'); 722 mouthOnOffOld = 2; 723//begin 724 rx 725 Serial.println("Starting rx"); 726 727 delay(10); // tweak delay 728 to accomodate uno 729 730 incomingMouthByte = Serial1.read(); 731 Serial1.flush(); 732 733 mouthOnOffAdjusted = incomingMouthByte; 734 Serial.print("mouthOnOffAdjusted 735 should be 2: "); 736 Serial.println(mouthOnOffAdjusted); 737 } 738 if(mouthOnOffNew 739 == 3){ 740 Serial.println("Starting tx"); 741 Serial1.flush(); 742 Serial1.write('3'); 743 744 mouthOnOffOld = 3; 745//begin rx 746 Serial.println("Starting rx"); 747 748 749 delay(10); // tweak delay to accomodate uno 750 751 // use a serial 752 available after flush funtion while or for loop or interrrupt or somethin 753 incomingMouthByte 754 = Serial1.read(); 755 Serial1.flush(); 756 mouthOnOffAdjusted = incomingMouthByte; 757 758 Serial.print("mouthOnOffAdjusted should be 3: "); 759 Serial.println(mouthOnOffAdjusted); 760 761 } 762 if(mouthOnOffNew == 4){ 763 Serial.println("Starting tx"); 764 765 Serial1.flush(); 766 Serial1.write('4'); 767 mouthOnOffOld = 4; 768//begin 769 rx 770 Serial.println("Starting rx"); 771 772 delay(10); // tweak delay 773 to accomodate uno 774 775 // use a serial available after flush funtion 776 while or for loop or interrrupt or somethin 777 incomingMouthByte = Serial1.read(); 778 779 Serial1.flush(); 780 mouthOnOffAdjusted = incomingMouthByte; 781 Serial.print("mouthOnOffAdjusted 782 should be 4: "); 783 Serial.println(mouthOnOffAdjusted); 784 } 785 786 787 788 else if(mouthOnOffAdjusted <= 1 && 4 >= mouthOnOffAdjusted){ 789 Serial.println("error 790 reply wasn't like expected"); 791 Serial.print("instead, the adjusted reply 792 was"); 793 794 delay(10); // tweak delay to accomodate uno 795 796 incomingMouthByte 797 = Serial1.read(); 798 Serial1.flush(); 799 mouthOnOffAdjusted = incomingMouthByte; 800 801 Serial.print("mouthOnOffAdjusted: "); 802 Serial.println(mouthOnOffAdjusted); 803 804 } 805 } 806 else if(mouthOnOffOld = mouthOnOffNew){ 807 } 808 Serial.flush(); 809 810 Serial1.flush(); 811} 812 813//--------------------------end mouthUnoTxRx -------------------------------------- 814//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 815//--------------------------begin 816 headUnoTxRx---------------------------------- 817 818void headUnoTxRx(){ 819 if(headOnOffNew 820 != headOnOffOld){ 821 Serial.println("starting txrx"); 822 if(headOnOffNew 823 == 1){ 824 Serial.println("Starting tx"); 825 Serial2.flush(); 826 Serial2.write('1'); 827 828 headOnOffOld = 1; 829//begin rx 830 Serial.println("Starting rx"); 831 832 833 delay(10); // tweak delay to accomodate uno 834 835 // use a serial 836 available after flush funtion while or for loop or interrrupt or somethin instead 837 of delay 838 incomingHeadByte = Serial2.read(); 839 Serial2.flush(); 840 841 headOnOffAdjusted = incomingHeadByte; 842 Serial.print("headOnOffAdjusted 843 should be 1: "); 844 Serial.println(headOnOffAdjusted); 845 } 846 if(headOnOffNew 847 == 2){ 848 Serial.println("Starting tx"); 849 Serial2.flush(); 850 Serial2.write('2'); 851 852 headOnOffOld = 2; 853//begin rx 854 Serial.println("Starting rx"); 855 856 857 delay(10); // tweak delay to accomodate uno 858 859 incomingHeadByte 860 = Serial2.read(); 861 Serial2.flush(); 862 headOnOffAdjusted = incomingHeadByte; 863 864 Serial.print("headOnOffAdjusted should be 2: "); 865 Serial.println(headOnOffAdjusted); 866 867 } 868 else if(headOnOffAdjusted != 1 && headOnOffAdjusted != 2){ 869 Serial.println("error 870 reply wasn't like expected"); 871 Serial.print("instead, the adjusted reply 872 was"); 873 874 delay(10); // tweak delay to accomodate uno 875 876 incomingHeadByte 877 = Serial2.read(); 878 Serial2.flush(); 879 headOnOffAdjusted = incomingHeadByte; 880 881 Serial.print("headOnOffAdjusted: "); 882 Serial.println(headOnOffAdjusted); 883 884 } 885 } 886 else if(headOnOffOld = headOnOffNew){ 887 } 888 Serial.flush(); 889 890 Serial2.flush(); 891} 892 893//--------------------------end headUnoTxRx -------------------------------------- 894//**************************************************************************************************** 895//**************************************************************************************************** 896 897//--------------------------begin 898 tftDisplay code---------------------------------- 899void tftDisplay(){ 900 Point 901 p = ts.getPoint(); 902 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 903 p.y = map(p.y, 904 TS_MINY, TS_MAXY, 0, 320); 905 906 Tft.fillRectangle(70, 100, 60, 30, BLACK); 907 908 Tft.drawNumber((buttonGroup), 70, 100, 3, GREEN); 909 Tft.fillRectangle(140, 910 100, 60, 30, BLACK); 911 Tft.drawNumber((mouthOnOffNew), 140, 100, 3, GREEN); 912 913 Tft.fillRectangle(160, 100, 60, 30, BLACK); 914 Tft.drawNumber((headOnOffNew), 915 160, 100, 3, GREEN); 916 Tft.fillRectangle(0, 225, 60, 30, BLACK); 917 Tft.drawNumber((p.x), 918 0, 225, 3, GREEN); 919 Tft.fillRectangle(180, 225, 60, 30, BLACK); 920 Tft.drawNumber((p.y), 921 180, 225, 3, GREEN); 922 Tft.fillRectangle(100, 225, 60, 30, BLACK); 923 Tft.drawNumber((buttonPressed), 924 100, 225, 3, GREEN); 925 Tft.fillRectangle(120, 290, 60, 30, BLACK); 926 Tft.drawNumber((currentScreen), 927 120, 290, 3, GREEN); 928 929 930}// void tftDisplay 931//--------------------------end 932 tftDisplay code------------------------------------ 933 934//**************************************************************************************************** 935//**************************************************************************************************** 936 937//-------------------------- 938 begin mouth on off function -------------------------- 939//-------------------------- 940 end mouth on off function -------------------------- 941 942//**************************************************************************************************** 943//**************************************************************************************************** 944 945//-------------------------- 946 begin head on off function -------------------------- 947//-------------------------- 948 end head on off function ------------------------- 949 950//**************************************************************************************************** 951//**************************************************************************************************** 952 953//-------------------------- 954 begin serial display function -------------------------- 955void showStuff(){ 956 957 Serial.println("------/ last update /-------"); 958// Serial.println("------begin 959 display-------"); 960 Serial.print("buttonPressed "); 961 Serial.println(buttonPressed); 962 963 Serial.print("x "); 964 Serial.println(x); 965 Serial.print("y "); 966 967 Serial.println(y); 968 Serial.print("z "); 969 Serial.println(z); 970 Serial.print("currentScreen 971 "); 972 Serial.println(currentScreen); 973// Serial.println("-------end display--------"); 974 975 Serial.println(""); 976 Serial.println(""); 977 Serial.println(""); 978 979 } 980//-------------------------- end serial display function ------------------------- 981 982 983//**************************************************************************************************** 984//**************************************************************************************************** 985 986//--------------------------- 987 Primary screen maps -------------------------------- 988/* 989 990 991 992screen 993 0000 A)Main Controls 994 995 screen 0001 a)motor controls 996 997 screen 0001 998 b) Touch Screen Timeout 999 screen 0011 -longer 1000 screen 0011 -shorter 1001 1002 screen 0011 -reset 1003 1004 screen 0001 c)sensor monitors 1005 screen 0021 1006 -head reports 1007 screen 0121 *report pir detection 1008 screen 0121 1009 *report pot position 1010 screen 0021 -mouth reports 1011 screen 0221 *graves 1012 sense 1013 screen 0221 *echo sense 1014 screen 0221 *report mouth servo 1015 position 1016// screen 0221 *adjust sensitivity? 1017 1018screen 0000 B)Mouth 1019 Control 1020 1021 screen 0002 a)test button 1022 screen 0012 -open 1023 screen 1024 0012 -close 1025 1026 screen 0002 b)sound sensors on/off 1027 1028 screen 0022 1029 -echo sense 1030 screen 0122 *on 1031 screen 0122 *off 1032 screen 1033 0122 *monitor sensor 1034 1035 screen 0022 -graves sense 1036 screen 0222 1037 *on 1038 screen 0222 *off 1039 screen 0222 *monitor sensors 1040 1041 1042 screen 0002 c)sound sensor status 1043 screen 0032 -echo 1044 screen 0032 1045 -graves 1046 1047screen 0000 C)Head Control 1048 screen 0003 a)head motor on/off 1049 1050 screen 0013 -on 1051 screen 0013 -off 1052 screen 0003 b)manual point 1053 1054 screen 0023 -slider 1055*/ 1056//**************************************************************************************************** 1057//**************************************************************************************************** 1058//-------------------------- 1059 begin whatScreen function ------------------------- 1060//-------------------------- 1061 begin whatScreen function ------------------------- 1062//-------------------------- 1063 begin whatScreen function ------------------------- 1064//-------------------------- 1065 begin whatScreen function ------------------------- 1066 1067int whatScreen(){ 1068 1069 if(x == 0){ 1070 if(buttonPressed == 1){ 1071 x = x + 1; 1072 Serial.println("x 1073 + 1"); 1074 } 1075 if(buttonPressed == 2){ 1076 x = x + 2; 1077 Serial.println("x 1078 + 2"); 1079 } 1080 if(buttonPressed == 3){ 1081 x = x + 3; 1082 Serial.println("x 1083 + 3"); 1084 } 1085 if(buttonPressed == 4){ 1086 x = 0; 1087 Serial.println("x 1088 = 0"); 1089 } 1090 if(buttonPressed == 5){ 1091 x = 0; 1092 y 1093 = 0; 1094 z = 0; 1095 Serial.println("xyz all 0"); 1096 } 1097 1098 } 1099 else if(x >> 0){ 1100 if(y == 0){ 1101 if(buttonPressed == 1102 1){ 1103 y = y + 10; 1104 Serial.println("y + 10"); 1105 } 1106 1107 if(buttonPressed == 2){ 1108 y = y + 20; 1109 Serial.println("y 1110 + 20"); 1111 } 1112 if(buttonPressed == 3){ 1113 y = y + 30; 1114 1115 Serial.println("y + 30"); 1116 } 1117 if(buttonPressed == 1118 4){ 1119 x = 0; 1120 Serial.println("x = 0"); 1121 } 1122 1123 if(buttonPressed == 5){ 1124 x = 0; 1125 y = 0; 1126 z 1127 = 0; 1128 Serial.println("xyz all 0"); 1129 } 1130 } 1131 else 1132 if (y >> 0){ 1133 if(buttonPressed == 1){ 1134 z = z + 100; 1135 1136 Serial.println("z + 100"); 1137 } 1138 if(buttonPressed 1139 == 2){ 1140 z = z + 200; 1141 Serial.println("z + 200"); 1142 1143 } 1144 if(buttonPressed == 3){ 1145 if(currentScreen 1146 != 31){ 1147 z = z + 300; 1148 Serial.println("z + 300"); 1149 1150 } 1151 } 1152 if(buttonPressed == 4){ 1153 if(z 1154 == 0){ 1155 y = 0; 1156 Serial.println("y = 0"); 1157 } 1158 1159 else if(z >> 0){ 1160 z = 0; 1161 Serial.println("z 1162 = 0"); 1163 } 1164 } 1165 if(buttonPressed == 5){ 1166 1167 x = 0; 1168 y = 0; 1169 z = 0; 1170 Serial.println("xyz 1171 all 0"); 1172 } 1173 }//y>0 1174 }//x>0 1175 currentScreen = 1176 z+y+x; 1177 1178 1179//================button group exceptions================ 1180//================button 1181 group exceptions================ 1182 if(currentScreen == 111){ // HEAD MOTOR CONTOL 1183 1184 buttonGroup=1; 1185 } 1186 if(currentScreen == 12){ // MOUTH MOTOR CONTOL 1187 1188 buttonGroup=1; 1189 } 1190 if(currentScreen == 13){ // HEAD MOTOR CONTOL 1191 1192 buttonGroup=2; 1193 } 1194 if(currentScreen == 211){ // MOUTH MOTOR CONTOL 1195 1196 buttonGroup=2; 1197 } 1198 if(currentScreen == 31){ // BACKLIGHTIMER 1199 buttonGroup=3; 1200 1201 } 1202//================button group exceptions================ 1203//================button 1204 group exceptions================ 1205 1206} 1207//-------------------------- end whatScreen 1208 function ------------------------- 1209//-------------------------- end whatScreen 1210 function ------------------------- 1211//-------------------------- end whatScreen 1212 function ------------------------- 1213//-------------------------- end whatScreen 1214 function ------------------------- 1215//-------------------------- end whatScreen 1216 function ------------------------- 1217 1218//**************************************************************************************************** 1219//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 1220//**************************************************************************************************** 1221//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1222//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1223 screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1224//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 1225//**************************************************************************************************** 1226//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 1227//**************************************************************************************************** 1228//-------------------------- 1229 begin callScreen function ------------------------- 1230//-------------------------- 1231 begin callScreen function ------------------------- 1232//-------------------------- 1233 begin callScreen function ------------------------- 1234//-------------------------- 1235 begin callScreen function ------------------------- 1236//-------------------------- 1237 begin callScreen function ------------------------- 1238//-------------------------- 1239 begin callScreen function ------------------------- 1240//-------------------------- 1241 begin callScreen function ------------------------- 1242//-------------------------- 1243 begin callScreen function ------------------------- 1244//-------------------------- 1245 begin callScreen function ------------------------- 1246//-------------------------- 1247 begin callScreen function ------------------------- 1248//-------------------------- 1249 begin callScreen function ------------------------- 1250 1251int callScreen(){ 1252 1253 Tft.fillRectangle(0, 0, 240, 320, BLACK); 1254 1255//<><><><><><><><><><><><><><><><><><><><><><><><> 1256//<><><><><><><><> 1257 begin screen 0000 master <><><><><><><><> 1258//<><><><><><><><><><><><><><><><><><><><><><><><> 1259if(currentScreen 1260 == 0){ 1261 // " " 1262 Tft.drawString("GRAVES",0,5,4, 1263 GREEN); 1264 Tft.drawString("INTERFACE",18,50,4,GREEN); 1265 Tft.drawString("Main 1266 Controls", 05,130, 3, GREEN); 1267 Tft.drawString("Mouth Control", 05, 195, 1268 3, CYAN); 1269 Tft.drawString("Head Control", 10, 260, 3, BLUE); 1270} 1271//<><><><><><><><><><><><><><><><><><><><><><><><> 1272//<><><><><><><><> 1273 end screen 0000 master <><><><><><><><><> 1274//<><><><><><><><><><><><><><><><><><><><><><><><> 1275 1276//<><><><><><><><><><><><><><><><><><><><><><><><> 1277//<><><><><><><><> 1278 begin screen 0001 <><><><><><><><> 1279//<><><><><><><><><><><><><><><><><><><><><><><><> 1280 1281 if(currentScreen == 1){ 1282 // " " 1283 Tft.drawString("MAIN", 1284 65, 5, 4, GREEN); 1285 Tft.drawString("CONTROLS", 25, 50, 4, GREEN); 1286 Tft.drawString("Motors 1287 Power", 15, 130, 3, RED); 1288 Tft.drawString("Sensors", 55, 195, 3, YELLOW); 1289 1290 Tft.drawString("Light Timeout", 5, 260, 3, WHITE); 1291 Tft.drawString("<", 1292 0, 160, 3, GREEN); // back button 1293} 1294//<><><><><><><><><><><><><><><><><><><><><><><><> 1295//<><><><><><><><> 1296 end screen 0001 <><><><><><><><><> 1297//<><><><><><><><><><><><><><><><><><><><><><><><> 1298 1299 1300//<><><><><><><><><><><><><><><><><><><><><><><><> 1301//<><><><><><><><> 1302 begin screen 0011 <><><><><><><><> 1303//<><><><><><><><><><><><><><><><><><><><><><><><> 1304 1305 if(currentScreen == 11){ 1306 // " " 1307 Tft.drawString("MOTOR", 1308 60, 5, 4, RED); 1309 Tft.drawString("CONTROLS", 20, 50, 4, RED); 1310 Tft.drawString("Head 1311 Motor", 30, 130, 3, BLUE); 1312 Tft.drawString("Mouth Motor", 25, 195, 3, 1313 CYAN); 1314 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1315} 1316//<><><><><><><><><><><><><><><><><><><><><><><><> 1317//<><><><><><><><> 1318 end screen 0013 <><><><><><><><><> 1319//<><><><><><><><><><><><><><><><><><><><><><><><> 1320 1321//<><><><><><><><><><><><><><><><><><><><><><><><> 1322//<><><><><><><><> 1323 begin screen 0111 <><><><><><><><> 1324//<><><><><><><><><><><><><><><><><><><><><><><><> 1325 1326 if(currentScreen == 111){ 1327 // " " 1328 Tft.drawString("HEAD 1329 MOTOR",0,5,4,BLUE); 1330 Tft.drawString("CONTROL", 40, 50, 4, BLUE); 1331 1332 Tft.drawString("On", 100, 130, 3, GREEN); 1333 Tft.drawString("Off", 1334 95, 195, 3, RED); 1335 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1336} 1337//<><><><><><><><><><><><><><><><><><><><><><><><> 1338//<><><><><><><><> 1339 end screen 0111 <><><><><><><><><> 1340//<><><><><><><><><><><><><><><><><><><><><><><><> 1341 1342//<><><><><><><><><><><><><><><><><><><><><><><><> 1343//<><><><><><><><> 1344 begin screen 0211 <><><><><><><><> 1345//<><><><><><><><><><><><><><><><><><><><><><><><> 1346 1347 if(currentScreen == 211){ 1348 // " " 1349 Tft.drawString("MOUTH", 1350 60, 5, 4, CYAN); 1351 Tft.drawString("MOTOR", 60, 50, 4, CYAN); 1352 Tft.drawString("On", 1353 100, 130, 3, GREEN); 1354 Tft.drawString("Off", 95, 195, 3, RED); 1355 Tft.drawString("<", 1356 0, 160, 3, GREEN); // back button 1357} 1358//<><><><><><><><><><><><><><><><><><><><><><><><> 1359//<><><><><><><><> 1360 end screen 0211 <><><><><><><><><> 1361//<><><><><><><><><><><><><><><><><><><><><><><><> 1362 1363//<><><><><><><><><><><><><><><><><><><><><><><><> 1364//<><><><><><><><> 1365 begin screen 0031 <><><><><><><><> 1366//<><><><><><><><><><><><><><><><><><><><><><><><> 1367 1368 if(currentScreen == 31){ 1369 // " " 1370 Tft.drawString("BACKLIGHT",10,5,4,WHITE); 1371 1372 Tft.drawString("TIME OUT",20,50,4,WHITE); 1373 Tft.drawString("2 minutes", 1374 35,130, 3, GREEN); 1375 Tft.drawString("15 seconds", 30, 195, 3, RED); 1376 1377 Tft.drawString("5 seconds", 35, 260, 3, WHITE); 1378 Tft.drawString("<", 1379 0, 160, 3, GREEN); // back button 1380} 1381 1382//<><><><><><><><><><><><><><><><><><><><><><><><> 1383//<><><><><><><><> 1384 end screen 0031 <><><><><><><><><> 1385//<><><><><><><><><><><><><><><><><><><><><><><><> 1386 1387//<><><><><><><><><><><><><><><><><><><><><><><><> 1388//<><><><><><><><> 1389 begin screen 0021 <><><><><><><><> 1390//<><><><><><><><><><><><><><><><><><><><><><><><> 1391 1392 if(currentScreen == 21){ 1393 // " " 1394 Tft.drawString("INCOMING", 1395 20, 5, 4, GREEN); 1396 Tft.drawString("SENSORS", 30, 50, 4,YELLOW); 1397 Tft.drawString("Head 1398 Sensors", 15, 130, 3, YELLOW); 1399 Tft.drawString("Mouth Sensors", 05, 195, 1400 3, YELLOW); 1401 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1402} 1403//<><><><><><><><><><><><><><><><><><><><><><><><> 1404//<><><><><><><><> 1405 end screen 0021 <><><><><><><><><> 1406//<><><><><><><><><><><><><><><><><><><><><><><><> 1407 1408//<><><><><><><><><><><><><><><><><><><><><><><><> 1409//<><><><><><><><> 1410 begin screen 0121 <><><><><><><><> 1411//<><><><><><><><><><><><><><><><><><><><><><><><> 1412 1413 if(currentScreen == 121){ 1414 // " " 1415 Tft.drawString("HEAD", 1416 65, 5, 4, BLUE); 1417 Tft.drawString("SENSORS", 30, 50, 4, YELLOW); 1418 Tft.drawString("PIR 1419 position ", 10, 130, 3, YELLOW); 1420 Tft.drawString("detected", 05, 195, 1421 3, YELLOW); 1422 Tft.drawChar(incomingHeadByte, 185, 195, 3, YELLOW); 1423 Tft.drawString("<", 1424 0, 160, 3, GREEN); // back button 1425} 1426//<><><><><><><><><><><><><><><><><><><><><><><><> 1427//<><><><><><><><> 1428 end screen 0121 <><><><><><><><><> 1429//<><><><><><><><><><><><><><><><><><><><><><><><> 1430 1431//<><><><><><><><><><><><><><><><><><><><><><><><> 1432//<><><><><><><><> 1433 begin screen 0221 <><><><><><><><> 1434//<><><><><><><><><><><><><><><><><><><><><><><><> 1435 1436 if(currentScreen == 221){ 1437 // " " 1438 Tft.drawString("MOUTH", 1439 55, 5, 4, CYAN); 1440 Tft.drawString("SENSORS", 30, 50, 4, YELLOW); 1441 Tft.drawString("Echo 1442 Sense", 30, 130, 3, YELLOW); 1443 Tft.drawString("Graves Sense", 10, 195, 1444 3, YELLOW); 1445 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1446} 1447//<><><><><><><><><><><><><><><><><><><><><><><><> 1448//<><><><><><><><> 1449 end screen 0221 <><><><><><><><><> 1450//<><><><><><><><><><><><><><><><><><><><><><><><> 1451 1452 1453//<><><><><><><><><><><><><><><><><><><><><><><><> 1454//<><><><><><><><> 1455 begin screen 0002 <><><><><><><><> 1456//<><><><><><><><><><><><><><><><><><><><><><><><> 1457 1458 if(currentScreen == 2){ 1459 // " " 1460 Tft.drawString("MOUTH", 1461 50, 5, 4, CYAN); 1462 Tft.drawString("CONTROL", 30, 50, 4, CYAN); 1463 Tft.drawString("Motor 1464 on/off", 15, 130, 3, RED); 1465 Tft.drawString("Sensor on/off", 05, 195, 1466 3, YELLOW); 1467 Tft.drawString("Monitor", 5, 260, 3, YELLOW); 1468 Tft.drawChar(incomingMouthByte, 1469 185, 260, 3, YELLOW); 1470 Tft.drawString("<", 0, 160, 3, GREEN); // back 1471 button 1472 } 1473//<><><><><><><><><><><><><><><><><><><><><><><><> 1474//<><><><><><><><> 1475 end screen 0002 <><><><><><><><><> 1476//<><><><><><><><><><><><><><><><><><><><><><><><> 1477 1478 1479//<><><><><><><><><><><><><><><><><><><><><><><><> 1480//<><><><><><><><> 1481 begin screen 0012 <><><><><><><><> 1482//<><><><><><><><><><><><><><><><><><><><><><><><> 1483 1484 if(currentScreen == 12){ 1485 // " " 1486 Tft.drawString("MOUTH", 1487 60, 5, 4, CYAN); 1488 Tft.drawString("MOTOR", 60, 50, 4, CYAN); 1489 Tft.drawString("On", 1490 100, 130, 3, GREEN); 1491 Tft.drawString("Off", 95, 195, 3, RED); 1492 Tft.drawString("<", 1493 0, 160, 3, GREEN); // back button 1494} 1495//<><><><><><><><><><><><><><><><><><><><><><><><> 1496//<><><><><><><><> 1497 end screen 0012 <><><><><><><><><> 1498//<><><><><><><><><><><><><><><><><><><><><><><><> 1499 1500 1501//<><><><><><><><><><><><><><><><><><><><><><><><> 1502//<><><><><><><><> 1503 begin screen 0022 <><><><><><><><> 1504//<><><><><><><><><><><><><><><><><><><><><><><><> 1505 1506 if(currentScreen == 22){ 1507 // " " 1508 Tft.drawString("SENSOR", 1509 40, 5, 4, YELLOW); 1510 Tft.drawString("SELECT", 40, 50, 4,YELLOW); 1511 Tft.drawString("Echo 1512 Sense", 30, 130, 3, YELLOW); 1513 Tft.drawString("Graves Sense", 10, 195, 1514 3, YELLOW); 1515 Tft.drawString("Monitor Both", 10, 260, 3, YELLOW); 1516 Tft.drawString("<", 1517 0, 160, 3, GREEN); // back button 1518} 1519//<><><><><><><><><><><><><><><><><><><><><><><><> 1520//<><><><><><><><> 1521 end screen 0022 <><><><><><><><><> 1522//<><><><><><><><><><><><><><><><><><><><><><><><> 1523 1524 1525 1526//<><><><><><><><><><><><><><><><><><><><><><><><> 1527//<><><><><><><><> 1528 begin screen 0122 <><><><><><><><> 1529//<><><><><><><><><><><><><><><><><><><><><><><><> 1530 1531 if(currentScreen == 122){ 1532 // " " 1533 Tft.drawString("ECHO", 1534 70, 5, 4, YELLOW); 1535 Tft.drawString("SENSOR", 35, 50, 4, YELLOW); 1536 Tft.drawString("On", 1537 100, 130, 3, GREEN); 1538 Tft.drawString("Off", 95, 195, 3, RED); 1539 Tft.drawString("Monitor", 1540 5, 260, 3, GREEN); 1541 Tft.drawChar(incomingMouthByte, 185, 260, 3, YELLOW); 1542 1543 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1544} 1545//<><><><><><><><><><><><><><><><><><><><><><><><> 1546//<><><><><><><><> 1547 end screen 0122 <><><><><><><><><> 1548//<><><><><><><><><><><><><><><><><><><><><><><><> 1549 1550//<><><><><><><><><><><><><><><><><><><><><><><><> 1551//<><><><><><><><> 1552 begin screen 0222 <><><><><><><><> 1553//<><><><><><><><><><><><><><><><><><><><><><><><> 1554 1555 if(currentScreen == 222){ 1556 // " " 1557 Tft.drawString("GRAVES",35,5,4,BLUE); 1558 1559 Tft.drawString("SENSOR",35,50,4,YELLOW); 1560 Tft.drawString("On", 1561 100, 130, 3, GREEN); 1562 Tft.drawString("Off", 95, 195, 3, RED); 1563 Tft.drawString("Monitor", 1564 5, 260, 3, GREEN); 1565 Tft.drawChar(incomingMouthByte, 185, 260, 3, YELLOW); 1566 1567 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1568} 1569//<><><><><><><><><><><><><><><><><><><><><><><><> 1570//<><><><><><><><> 1571 end screen 0222 <><><><><><><><><> 1572//<><><><><><><><><><><><><><><><><><><><><><><><> 1573 1574//<><><><><><><><><><><><><><><><><><><><><><><><> 1575//<><><><><><><><> 1576 begin screen 0032 <><><><><><><><> 1577//<><><><><><><><><><><><><><><><><><><><><><><><> 1578 1579 if(currentScreen == 32){ 1580 // " " 1581 Tft.drawString("ALL", 1582 90, 5, 4, BLUE); 1583 Tft.drawString("SENSORS", 35, 50, 4, YELLOW); 1584 Tft.drawString("Echo", 1585 35, 130, 3, BLUE); 1586 Tft.drawChar(incomingMouthByte, 185, 130, 3, YELLOW); 1587 1588 Tft.drawString("Graves", 30, 195, 3, GREEN); 1589 Tft.drawChar(incomingMouthByte, 1590 185, 130, 3, YELLOW); 1591 Tft.drawString("<", 0, 160, 3, GREEN); // back 1592 button 1593} 1594//<><><><><><><><><><><><><><><><><><><><><><><><> 1595//<><><><><><><><> 1596 end screen 0032 <><><><><><><><><> 1597//<><><><><><><><><><><><><><><><><><><><><><><><> 1598 1599//<><><><><><><><><><><><><><><><><><><><><><><><> 1600//<><><><><><><><> 1601 begin screen 0003 <><><><><><><><> 1602//<><><><><><><><><><><><><><><><><><><><><><><><> 1603 1604 if(currentScreen == 3){ 1605 // " " 1606 Tft.drawString("HEAD", 1607 70, 5, 4, BLUE); 1608 Tft.drawString("CONTROL", 30, 50, 4, RED); 1609 Tft.drawString("Motor 1610 On/Off", 15, 130, 3, RED); 1611 Tft.drawString("Manual Point", 15, 195, 3, 1612 RED); 1613 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1614} 1615//<><><><><><><><><><><><><><><><><><><><><><><><> 1616//<><><><><><><><> 1617 end screen 0003 <><><><><><><><><> 1618//<><><><><><><><><><><><><><><><><><><><><><><><> 1619 1620//<><><><><><><><><><><><><><><><><><><><><><><><> 1621//<><><><><><><><> 1622 begin screen 0013 <><><><><><><><> 1623//<><><><><><><><><><><><><><><><><><><><><><><><> 1624 1625 if(currentScreen == 13){ 1626 // " " 1627 Tft.drawString("HEAD", 1628 70, 5, 4, BLUE); 1629 Tft.drawString("MOTOR", 60, 50, 4, RED); 1630 Tft.drawString("On", 1631 100, 130, 3, GREEN); 1632 Tft.drawString("Off", 95, 195, 3, RED); 1633 Tft.drawString("<", 1634 0, 160, 3, GREEN); // back button 1635} 1636//<><><><><><><><><><><><><><><><><><><><><><><><> 1637//<><><><><><><><> 1638 end screen 0013 <><><><><><><><><> 1639//<><><><><><><><><><><><><><><><><><><><><><><><> 1640 1641//<><><><><><><><><><><><><><><><><><><><><><><><> 1642//<><><><><><><><> 1643 begin screen 0023 <><><><><><><><> 1644//<><><><><><><><><><><><><><><><><><><><><><><><> 1645 1646 if(currentScreen == 23){ 1647 // " " 1648 Tft.drawString("HEAD", 1649 70, 5, 4, BLUE); 1650 Tft.drawString("POINTER", 35, 50, 4, RED); 1651 Tft.drawString("Left", 1652 85, 130, 3, RED); 1653 Tft.drawString("Right", 75, 195, 3, RED); 1654 Tft.drawString("Center", 1655 65, 260, 3, RED); 1656 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1657} 1658//<><><><><><><><><><><><><><><><><><><><><><><><> 1659//<><><><><><><><> 1660 end screen 0023 <><><><><><><><><> 1661//<><><><><><><><><><><><><><><><><><><><><><><><> 1662 1663 1664//<><><><><><><><><><><><><><><><><><><><><><><><> 1665//<><><><><><><><> 1666 begin screen 0422 <><><><><><><><> 1667//<><><><><><><><><><><><><><><><><><><><><><><><> 1668 1669 if(currentScreen == 422){ 1670 // " " 1671 Tft.drawString("Command 1672 Sent",0,5,3,BLUE); 1673 Tft.drawString("Press Back to",0,55,3,YELLOW); 1674 1675 Tft.drawString("Contiue", 50,105, 3, BLUE); 1676 Tft.drawString("<", 1677 0, 160, 3, GREEN); // back button 1678} 1679//<><><><><><><><><><><><><><><><><><><><><><><><> 1680//<><><><><><><><> 1681 end screen 0422 <><><><><><><><><> 1682//<><><><><><><><><><><><><><><><><><><><><><><><> 1683 1684 1685////<><><><><><><><><><><><><><><><><><><><><><><><> 1686////<><><><><><><><> 1687 begin screen lost <><><><><><><><> 1688////<><><><><><><><><><><><><><><><><><><><><><><><> 1689// 1690 else if(currentScreen){ 1691// // " " 1692// 1693 Tft.drawString("Screen not",0,5,3,BLUE); 1694// Tft.drawString("found. 1695 Please",40,50,3,YELLOW); 1696// Tft.drawString("use the back", 80,130, 3, 1697 BLUE); 1698// Tft.drawString("button to", 05, 195, 3, GREEN); 1699// Tft.drawString("return 1700 to fun", 10, 260, 3, GREEN); 1701// Tft.drawString("<", 0, 160, 3, GREEN); 1702 // back button 1703//} 1704////<><><><><><><><><><><><><><><><><><><><><><><><> 1705////<><><><><><><><> 1706 end screen lost <><><><><><><><><> 1707////<><><><><><><><><><><><><><><><><><><><><><><><> 1708 1709 1710}// 1711 callScreen 1712//-------------------------- end callScreen function ------------------------- 1713//-------------------------- 1714 end callScreen function ------------------------- 1715//-------------------------- 1716 end callScreen function ------------------------- 1717//-------------------------- 1718 end callScreen function ------------------------- 1719//-------------------------- 1720 end callScreen function ------------------------- 1721//-------------------------- 1722 end callScreen function ------------------------- 1723//-------------------------- 1724 end callScreen function ------------------------- 1725//-------------------------- 1726 end callScreen function ------------------------- 1727//-------------------------- 1728 end callScreen function ------------------------- 1729//-------------------------- 1730 end callScreen function ------------------------- 1731//-------------------------- 1732 end callScreen function ------------------------- 1733//-------------------------- 1734 end callScreen function ------------------------- 1735//-------------------------- 1736 end callScreen function ------------------------- 1737 1738 1739//**************************************************************************************************** 1740//**************************************************************************************************** 1741 1742 1743 1744 1745 1746 1747 1748//**************************************************************************************************** 1749//**************************************************************************************************** 1750 1751// 1752 fin
22102018 graves uno head code
c_cpp
code for arduino uno that controls head movement
1/* 2last edit monday oct 22 2018 3 4gravesunohead 5 6graves project 7arduino Uno 8Slave 1 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17*/ 18 19 20// L298n motor controller code 21// connect motor controller pins to Arduino digital pins 22// motor one 23int enA = 10; 24int in1 = 8; 25int in2 = 9; 26// L298n motor controller code 27 28// pot switches 29//int potControlPin = A1; // analog pin used to connect the controller potentiometer 30//int valControl; // variable to read the value from the analog pin for control input 31//int potControl = 0; // variable to store the servo position from the controller pot switch 32int potPositionPin = A0; // analog pin used to connect the position monitoring potentiometer 33int valPosition; // variable to read the value from the analog pin connected to position monitor 34int potPosition = 0; // variable to store the servo position of the monitoring pot switch 35// pot switches 36int detectedPosition; // variable to store info 37boolean pirStatus; 38 39int servangle = 0; // servo angle variable 40int pirNo[] = {3,4,5,6,7}; // pir pin numbers 41int pirPrevLow[] = {1,1,1,1,1}; // previously low flag set to true 42int pirPrevUsed[] = {0,0,0,0,0}; // has pir been on used before going low 43int pirPos[] = {10,60,100,140,170}; // positions for servo (0-180) 44int curPosPir = 0; 45int pirPin = 3; 46 47 48unsigned long time; 49 50// for blinking 51const int ledPin = LED_BUILTIN;// the number of the LED pin 52int ledState = LOW; // ledState used to set the LED 53unsigned long previousMillis = 0; // will store last time LED was updated 54 55long interval = 1; // interval at which to move servos (milliseconds) 56 57char incomingHeadByte; 58char outgoingHeadByte; 59int headOnOffAdjusted; 60int headOnOffOld; 61int headOnOffNew; 62 63 64void setup() { 65 delay(5000); 66 Serial.begin(9600); 67 incomingHeadByte = 0; // for incoming serial data 68 outgoingHeadByte = 0; // for a bit more talkative serial data 69 headOnOffAdjusted = 1; 70 headOnOffOld = 1; // stores head state from serial connection 71 headOnOffNew = 1; // stores head state from serial connection 72 73 74 time = millis(); 75 // motor control setup code 76 // set all the motor control pins to outputs 77 pinMode(enA, OUTPUT); 78 pinMode(in1, OUTPUT); 79 pinMode(in2, OUTPUT); 80 // motor control setup code 81 pinMode(LED_BUILTIN, OUTPUT); 82 83 // blink led to denote ready 84 blinkSlow(); 85} 86//---------------------end void setup----------------------- 87//---------------------end void setup----------------------- 88//---------------------end void setup----------------------- 89 90//---------------------begin void loop----------------------- 91//---------------------begin void loop----------------------- 92//---------------------begin void loop----------------------- 93 94void loop(){ 95 serialDoStuff(); 96 if(headOnOffNew == headOnOffOld){ 97 if(headOnOffNew == 1){ 98 sensePositionFunction(); 99 headTurn(); 100 } 101 if(headOnOffNew == 2){ 102 } 103 } 104 else if(headOnOffNew != headOnOffOld){ 105 headOnOffNew = headOnOffOld; 106 } 107} 108 109//---------------------end void loop----------------------- 110//---------------------end void loop----------------------- 111//---------------------end void loop----------------------- 112 113 114//********************************************************* 115//********************************************************* 116 117//---------------------begin serialDoStuff ----------------- 118void serialDoStuff(){ 119 if(Serial.available() > 0){ 120 incomingHeadByte = Serial.read(); 121 headOnOffAdjusted = incomingHeadByte - '0'; 122 if(headOnOffAdjusted == 1){ 123 Serial.flush(); 124// outgoingHeadByte = 1; 125// Serial.write(outgoingHeadByte); 126 headOnOffOld = 1; 127 } 128 else if(headOnOffAdjusted == 2){ 129 Serial.flush(); 130// outgoingHeadByte = 2; 131// Serial.write(outgoingHeadByte); 132 headOnOffOld = 2; 133 } 134 } 135} 136//---------------------end serialDoStuff----------------- 137 138//********************************************************* 139//********************************************************* 140//********************************************************* 141//********************************************************* 142// ++++++++++++++++++begin PIR function +++++++++++++++++++++++++++++++ 143void sensePositionFunction(){ 144 for(int j=0;j<5;j++){ // do this for each PIR in the array 145 pirPin=pirNo[j]; 146 pirStatus = digitalRead(pirPin); 147 if(pirStatus == HIGH){ // while cycling through the array if pirNo[j] is HIGH, do this 148 if(pirPrevLow[j]){ // and If pirNo[j] was previously low, do this 149 if(curPosPir != pirPin && pirPrevUsed[j] == 0){ // if pirNo[j] is HIGH and different than curPosPir, move to new position 150 curPosPir = pirPin; // keep current PIR 151 pirPrevUsed[j] = 1; 152 detectedPosition = pirPin; 153// return detectedPosition; 154 } 155 pirPrevLow[j] = 0; // pir is now not low 156 } 157 } 158 else{ 159 pirPrevLow[j] = 1; // pir is now low 160 pirPrevUsed[j] = 0; 161 } 162 } // end j number of pirs loop 163} 164//+++++++++++++++++++++++end PIR function +++++++++++++++++++++++++++++++ 165//********************************************************* 166//********************************************************* 167 168//---------------------begin headTurn ------------------- 169 170void headTurn() { 171 unsigned long currentMillis = millis(); 172 173 // begin potservo section for potentiometer control 174 int valControl = detectedPosition; // reads the value of the potentiometer (value between 0 and 1023) 175 int valPosition = analogRead(potPositionPin); 176 valControl = map(valControl, 0, 1023, 0, 10); // first 0 refers to pot minimum, second is pot maximum, 177 valPosition = map(valPosition, 0, 1023, 0, 10); // third is minimum servo angle, fourth is maximum servo angle 178// Serial.print("control "); 179// Serial.println(valControl); 180// Serial.print(" position "); 181// Serial.println(valPosition); 182 if (valPosition > valControl) 183 { 184 // do Thing A 185 // turn on motor A forward 186 if (currentMillis - previousMillis > interval) { 187 previousMillis = currentMillis; 188 // set speed to __ out of possible range 80~255 189 analogWrite(enA, 100); 190 digitalWrite(in1, HIGH); 191 digitalWrite(in2, LOW); 192 blinkSlow(); 193 outgoingHeadByte = '<'; 194 Serial.write(outgoingHeadByte); 195 } 196 } 197 else if (valPosition < valControl) 198 { 199 if (currentMillis - previousMillis > interval) { 200 previousMillis = currentMillis; 201 // do Thing B 202 // turn on motor A backward 203 // set speed to __ out of possible range 80~255 204 analogWrite(enA, 100); 205 digitalWrite(in1, LOW); 206 digitalWrite(in2, HIGH); 207 blinkFast(); 208 outgoingHeadByte = '>'; 209 Serial.write(outgoingHeadByte); 210 } 211 } 212 else 213 { 214 previousMillis = currentMillis; 215 // do Thing C 216 // turn motor off 217 analogWrite(enA, 0); 218 digitalWrite(in1, LOW); 219 digitalWrite(in2, LOW); 220 } 221} 222//---------------------end headTurn-------------------- 223//********************************************************* 224//********************************************************* 225//---------------------begin blink slow------------------- 226void blinkSlow(){ 227unsigned long currentMillis = millis(); 228const long interval1 = 500; 229 230 if(currentMillis - previousMillis >= interval1) { 231 previousMillis = currentMillis; 232 if(ledState == LOW){ 233 ledState = HIGH; 234 } 235 else{ 236 ledState = LOW; 237 } 238 digitalWrite(ledPin, ledState); 239 } 240} 241//---------------------end blink slow------------------- 242//---------------------begin blink fast ------------------- 243void blinkFast(){ 244unsigned long currentMillis = millis(); 245const long interval2 = 75; 246 if(currentMillis - previousMillis >= interval2){ 247 previousMillis = currentMillis; 248 if(ledState == LOW){ 249 ledState = HIGH; 250 } 251 else{ 252 ledState = LOW; 253 } 254 digitalWrite(ledPin, ledState); 255 } 256} 257//---------------------end blink fast ------------------- 258
button groups refined
c_cpp
this updated interface deals with changing button areas based on screen number
1/* 2last edit sunday oct 14 2018 midnight 3 4 5gravesmegamaster 6 7graves project 8arduino MEGA 2650 9Master 10coded from scratch by wylie jones 11wyliejones@gmail.com 12 13Graves multi arduino build 10/2018 14Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 15two arduino uno's 16slave1 arduino uno to sense sound from graves and echo dot to control mouth 17slave2 arduino uno to control passive sensor array and head servo 18 19sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 20 21 analogue pin speaker + 22 \ / (red from speaker) 23 \ / 24 \ / 25 *--------[=]-----------*---------[=]----------* 26 | resistor \ resistor | 27 | \ | 28 |(red with white) \ |to arduino ground (black with white) 29to arduino 5v+ speaker - 30 (black from speaker) 31 32*/ 33//end notes 34//end notes 35//end notes 36//end notes 37//end notes 38//end notes 39 40 41//********************************************************* 42//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 43//********************************************************* 44 45 46//begin declarations 47//begin declarations 48//begin declarations 49//begin declarations 50//begin declarations 51//begin declarations 52//begin declarations 53 54//#include <TFT.h> 55//#include <Servo.h> 56//#include <stdint.h> 57//#include <SD.h> 58#include <TFTv2.h> 59#include <SPI.h> 60#include <SeeedTouchScreen.h> 61 62//const int PIN_SD_CS = 4; // pin of sd card 63 64TouchScreen ts = TouchScreen(XP, YP, XM, YM); 65int zMax; // maximum pressure to detect 66int zMin; // minimum pressure to detect 67 68int buttonPressed; // stores which button was pressed 69unsigned long newButtonTime; // debounce 70unsigned long oldButtonTime; // debounce 71unsigned long buttonTimeDifference; // debounce 72unsigned long debounceTime; // debounce 73int buttonGroup; // sets kinds of buttons on screen 74 75int currentScreen; // identifies current screen by adding x y and z 76int x; // for ones 77int y; // for tens 78int z; // for hundreds 79 80unsigned long backlightTimer; // for backlight timeout 81int backLightState; // status of backlight 1 for on and 0 for off 82unsigned long backlightTimeDifference; 83unsigned long newBacklightTime; 84unsigned long oldBacklightTime; 85 86int incomingMouthByte; 87int outgoingMouthByte; 88int mouthOnOff; 89 90int incomingHeadByte; 91int outgoingHeadByte; 92int headOnOff; 93 94//end declarations 95//end declarations 96//end declarations 97//end declarations 98//end declarations 99//end declarations 100//end declarations 101//end declarations 102//end declarations 103 104//********************************************************* 105//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 106//********************************************************* 107 108// begin void setup 109// begin void setup 110// begin void setup 111// begin void setup 112// begin void setup 113// begin void setup 114// begin void setup 115// begin void setup 116// begin void setup 117// begin void setup 118// begin void setup 119void setup() { 120Serial.begin(9600); 121 oldButtonTime = millis(); 122 newButtonTime = millis(); 123 Tft.TFTinit(); // init TFT library 124 TFT_BL_ON; // turn on the background light 125 backLightState = 1; 126 x = 0; 127 y = 0; 128 z = 0; 129 buttonPressed = 4; 130 buttonGroup = 0; 131 incomingHeadByte = 0; 132 incomingMouthByte = 0; 133 134 //////////////////////////////// 135 //// manually set variables //// 136 //////////////////////////////// 137 138 debounceTime = 1000; // button debounce in milliseconds 139 zMax = 460; // maximum pressure to detect 140 zMin = 100; // minimum pressure to detect 141 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 142 143 144 currentScreen = 0; 145 callScreen(); 146 147} //void setup() 148// end void setup 149// end void setup 150// end void setup 151// end void setup 152// end void setup 153// end void setup 154// end void setup 155// end void setup 156 157//********************************************************* 158//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 159//********************************************************* 160 161// begin void loop 162// begin void loop 163// begin void loop 164// begin void loop 165// begin void loop 166// begin void loop 167// begin void loop 168// begin void loop 169// begin void loop 170// begin void loop 171// begin void loop 172// begin void loop 173// begin void loop 174// begin void loop 175 176void loop() { 177 tftBacklightTimeout(); // check time and turn off backlight 178 179if(buttonGroup == 0){ 180 tftButtonGroup0(); // gather information from touch screen touches 181 buttonTimeDifference = newButtonTime - oldButtonTime; 182 if(debounceTime < buttonTimeDifference){ 183 whatScreen(); 184 callScreen(); 185 oldButtonTime = newButtonTime; 186 showStuff(); // serial prints 187 tftDisplay(); // display x y coordinates on tft display 188 } 189} 190if(buttonGroup == 1){ 191 tftButtonGroup1(); // gather information from touch screen touches 192 buttonTimeDifference = newButtonTime - oldButtonTime; 193 if(debounceTime < buttonTimeDifference){ 194 whatScreen(); 195 callScreen(); 196 oldButtonTime = newButtonTime; 197 showStuff(); // serial prints 198 tftDisplay(); // display x y coordinates on tft display 199 } 200} 201if(buttonGroup == 2){ 202 tftButtonGroup2(); // gather information from touch screen touches 203 buttonTimeDifference = newButtonTime - oldButtonTime; 204 if(debounceTime < buttonTimeDifference){ 205 whatScreen(); 206 callScreen(); 207 oldButtonTime = newButtonTime; 208 showStuff(); // serial prints 209 tftDisplay(); // display x y coordinates on tft display 210 } 211} 212 213// serialDoStuff(); 214} //void loop() 215 216// end of void loop 217// end of void loop 218// end of void loop 219// end of void loop 220// end of void loop 221// end of void loop 222// end of void loop 223// end of void loop 224// end of void loop 225// end of void loop 226// end of void loop 227// end of void loop 228// end of void loop 229// end of void loop 230// end of void loop 231 232//**************************************************************************************************** 233//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 234//**************************************************************************************************** 235///////////////////////////////////////////////////////////////////////////////////////////////////////// 236///////////////////////////////////////// functions /////////////////////////////////////////////////// 237///////////////////////////////////////////////////////////////////////////////////////////////////////// 238//**************************************************************************************************** 239//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 240//**************************************************************************************************** 241 242//--------------------------begin tftBacklightTimeout---------------------------------- 243void tftBacklightTimeout(){ 244 newBacklightTime = millis(); 245 if(backLightState = 0){ 246 backlightTimeDifference = newBacklightTime - oldBacklightTime; 247 if(backlightTimer > backlightTimeDifference){ 248 backlightTimeDifference = newBacklightTime - oldBacklightTime; 249 TFT_BL_ON; // turn on the background light 250 backLightState = 1; 251 oldBacklightTime = millis(); 252 } 253 } 254 if(backLightState = 1){ 255 backlightTimeDifference = newBacklightTime - oldBacklightTime; 256 if(backlightTimer < backlightTimeDifference){ 257 backlightTimeDifference = newBacklightTime - oldBacklightTime; 258 TFT_BL_OFF; // turn off the background light 259 backLightState = 0; 260 oldBacklightTime = millis(); 261 } 262 } 263} 264//--------------------------end tftBacklightTimeout---------------------------------- 265 266//**************************************************************************************************** 267//**************************************************************************************************** 268 269//--------------------------begin tftButtonGroup0---------------------------------- 270//--------------------------begin tftButtonGroup0---------------------------------- 271//--------------------------begin tftButtonGroup0---------------------------------- 272//--------------------------begin tftButtonGroup0---------------------------------- 273int tftButtonGroup0(){ 274 Point p = ts.getPoint(); 275 if(zMin<p.z && p.z<zMax){ 276 TFT_BL_ON; // turn on the background light 277 backLightState = 1; 278 oldBacklightTime = millis(); 279 newButtonTime = millis(); 280 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 281 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 282//Button 1 283 if(75<p.x && p.x<140){ 284 if(100<p.y && p.y<164){ 285 buttonPressed = 1; 286 } 287//Button 2 288 if(164<p.y && p.y<240){ 289 buttonPressed = 2; 290 } 291//Button 3 292 if(240<p.y && p.y<310){ 293 buttonPressed = 3; 294 } 295 } 296 } 297//Button 4 298 if(10<p.x && p.x<75){ 299 if(100<p.y && p.y<240){ 300 buttonPressed = 4; 301 } 302 } 303}//void tftButtonGroup0 304//--------------------------end tftButtonGroup0 code---------------------------------- 305//--------------------------end tftButtonGroup0 code---------------------------------- 306//--------------------------end tftButtonGroup0 code---------------------------------- 307//--------------------------end tftButtonGroup0 code---------------------------------- 308//--------------------------end tftButtonGroup0 code---------------------------------- 309//**************************************************************************************************** 310//**************************************************************************************************** 311 312//--------------------------begin tftButtonGroup1---------------------------------- 313//--------------------------begin tftButtonGroup1---------------------------------- 314//--------------------------begin tftButtonGroup1---------------------------------- 315//--------------------------begin tftButtonGroup1---------------------------------- 316int tftButtonGroup1(){ // for mouth 317buttonPressed = 0; 318 Point p = ts.getPoint(); 319 if(zMin<p.z && p.z<zMax){ 320 TFT_BL_ON; // turn on the background light 321 backLightState = 1; 322 oldBacklightTime = millis(); 323 newButtonTime = millis(); 324 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 325 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 326//Button 1 327 if(75<p.x && p.x<140){ 328 if(100<p.y && p.y<164){ 329 mouthOnOff = 1; // on 330 } 331//Button 2 332 if(164<p.y && p.y<240){ 333 mouthOnOff = 0; // off 334 } 335//Button 3 336// if(240<p.y && p.y<310){ 337// buttonPressed = 3; 338// } 339 } 340 } 341//Button 4 342 if(10<p.x && p.x<75){ 343 if(100<p.y && p.y<240){ 344 buttonPressed = 4; 345 buttonGroup = 0; 346 } 347 } 348}//void tftButtonGroup1 349//--------------------------end tftButtonGroup1 code---------------------------------- 350//--------------------------end tftButtonGroup1 code---------------------------------- 351//--------------------------end tftButtonGroup1 code---------------------------------- 352//--------------------------end tftButtonGroup1 code---------------------------------- 353//--------------------------end tftButtonGroup1 code---------------------------------- 354//**************************************************************************************************** 355//**************************************************************************************************** 356 357//--------------------------begin tftButtonGroup2---------------------------------- 358//--------------------------begin tftButtonGroup2---------------------------------- 359//--------------------------begin tftButtonGroup2---------------------------------- 360//--------------------------begin tftButtonGroup2---------------------------------- 361int tftButtonGroup2(){ // for head 362buttonPressed = 0; 363 Point p = ts.getPoint(); 364 if(zMin<p.z && p.z<zMax){ 365 TFT_BL_ON; // turn on the background light 366 backLightState = 1; 367 oldBacklightTime = millis(); 368 newButtonTime = millis(); 369 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 370 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 371//Button 1 372 if(75<p.x && p.x<140){ 373 if(100<p.y && p.y<164){ 374 headOnOff = 1; // on 375 } 376//Button 2 377 if(164<p.y && p.y<240){ 378 headOnOff = 0; // off 379 } 380//Button 3 381// if(240<p.y && p.y<310){ 382// buttonPressed = 3; 383// } 384 } 385 } 386//Button 4 387 if(10<p.x && p.x<75){ 388 if(100<p.y && p.y<240){ 389 buttonPressed = 4; 390 buttonGroup = 0; 391 } 392 } 393}//void tftButtonGroup2 394//--------------------------end tftButtonGroup2 code---------------------------------- 395//--------------------------end tftButtonGroup2 code---------------------------------- 396//--------------------------end tftButtonGroup2 code---------------------------------- 397//--------------------------end tftButtonGroup2 code---------------------------------- 398//--------------------------end tftButtonGroup2 code---------------------------------- 399//**************************************************************************************************** 400//**************************************************************************************************** 401//-------------------------- begin whatScreen function ------------------------- 402//-------------------------- begin whatScreen function ------------------------- 403//-------------------------- begin whatScreen function ------------------------- 404//-------------------------- begin whatScreen function ------------------------- 405 406int whatScreen(){ 407 if(x == 0){ 408 if(buttonPressed == 1){ 409 x = x + 1; 410 Serial.println("x + 1"); 411 } 412 if(buttonPressed == 2){ 413 x = x + 2; 414 Serial.println("x + 2"); 415 } 416 if(buttonPressed == 3){ 417 x = x + 3; 418 Serial.println("x + 3"); 419 } 420 if(buttonPressed == 4){ 421 x = 0; 422 Serial.println("x = 0"); 423 } 424 if(buttonPressed == 5){ 425 x = 0; 426 y = 0; 427 z = 0; 428 Serial.println("xyz all 0"); 429 } 430 } 431 else if(x >> 0){ 432 if(y == 0){ 433 if(buttonPressed == 1){ 434 y = y + 10; 435 Serial.println("y + 10"); 436 } 437 if(buttonPressed == 2){ 438 y = y + 20; 439 Serial.println("y + 20"); 440 } 441 if(buttonPressed == 3){ 442 y = y + 30; 443 Serial.println("y + 30"); 444 } 445 if(buttonPressed == 4){ 446 x = 0; 447 Serial.println("x = 0"); 448 } 449 if(buttonPressed == 5){ 450 x = 0; 451 y = 0; 452 z = 0; 453 Serial.println("xyz all 0"); 454 } 455 } 456 else if (y >> 0){ 457 if(buttonPressed == 1){ 458 z = z + 100; 459 Serial.println("z + 100"); 460 } 461 if(buttonPressed == 2){ 462 z = z + 200; 463 Serial.println("z + 200"); 464 } 465 if(buttonPressed == 3){ 466 z = z + 300; 467 Serial.println("z + 300"); 468 } 469 if(buttonPressed == 4){ 470 if(z == 0){ 471 y = 0; 472 Serial.println("y = 0"); 473 } 474 else if(z >> 0){ 475 z = 0; 476 Serial.println("z = 0"); 477 } 478 } 479 if(buttonPressed == 5){ 480 x = 0; 481 y = 0; 482 z = 0; 483 Serial.println("xyz all 0"); 484 } 485 }//y>0 486 }//x>0 487 currentScreen = z+y+x; 488 if(currentScreen == 122){ 489 buttonGroup=1; 490 } 491 if(currentScreen == 222){ 492 buttonGroup=1; 493 } 494 if(currentScreen == 23){ 495 buttonGroup=2; 496 } 497} 498//-------------------------- end whatScreen function ------------------------- 499//-------------------------- end whatScreen function ------------------------- 500//-------------------------- end whatScreen function ------------------------- 501//-------------------------- end whatScreen function ------------------------- 502//-------------------------- end whatScreen function ------------------------- 503 504//**************************************************************************************************** 505//**************************************************************************************************** 506 507//--------------------------begin mouthUnoTxRx---------------------------------- 508 509void mouthUnoTxRx(){ 510 511 Serial1.write(mouthOnOff); // send a byte with the value 45 512 if(Serial1.available() > 0){ 513 incomingMouthByte = Serial1.read(); // read the incoming byte: 514 } 515} 516 517//--------------------------end mouthUnoTxRx -------------------------------------- 518//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 519//--------------------------begin headUnoTxRx -------------------------------------- 520 521// call slave1 arduino for data 522 523void headUnoTxRx(){ 524 Serial2.write(headOnOff); // send a byte with the value 45 525 if(Serial2.available() > 0){ 526 incomingHeadByte = Serial2.read(); // read the incoming byte: 527 } 528} 529 530// call slave2 arduino for data 531//--------------------------end headUnoTxRx -------------------------------------- 532 533//**************************************************************************************************** 534//**************************************************************************************************** 535 536//--------------------------begin tftDisplay code---------------------------------- 537void tftDisplay(){ 538 Point p = ts.getPoint(); 539 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 540 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 541 Tft.fillRectangle(0, 225, 60, 30, BLACK); 542 Tft.drawNumber((p.x), 0, 225, 3, GREEN); 543 Tft.fillRectangle(180, 225, 60, 30, BLACK); 544 Tft.drawNumber((p.y), 180, 225, 3, GREEN); 545 Tft.fillRectangle(100, 225, 60, 30, BLACK); 546 Tft.drawNumber((buttonPressed), 100, 225, 3, GREEN); 547 Tft.fillRectangle(70, 160, 60, 30, BLACK); 548 Tft.drawNumber((mouthOnOff), 70, 160, 3, GREEN); 549 Tft.fillRectangle(140, 160, 60, 30, BLACK); 550 Tft.drawNumber((headOnOff), 140, 160, 3, GREEN); 551 Tft.fillRectangle(120, 290, 60, 30, BLACK); 552 Tft.drawNumber((currentScreen), 120, 290, 3, GREEN); 553 554 555}// void tftDisplay 556//--------------------------end tftDisplay code------------------------------------ 557 558//**************************************************************************************************** 559//**************************************************************************************************** 560 561//-------------------------- begin mouth on off function -------------------------- 562//-------------------------- end mouth on off function -------------------------- 563 564//**************************************************************************************************** 565//**************************************************************************************************** 566 567//-------------------------- begin head on off function -------------------------- 568//-------------------------- end head on off function ------------------------- 569 570//**************************************************************************************************** 571//**************************************************************************************************** 572 573//-------------------------- begin serial display function -------------------------- 574void showStuff(){ 575 Serial.println("------/ last update /-------"); 576// Serial.println("------begin display-------"); 577 Serial.print("buttonPressed "); 578 Serial.println(buttonPressed); 579 Serial.print("x "); 580 Serial.println(x); 581 Serial.print("y "); 582 Serial.println(y); 583 Serial.print("z "); 584 Serial.println(z); 585 Serial.print("currentScreen "); 586 Serial.println(currentScreen); 587// Serial.println("-------end display--------"); 588 Serial.println(""); 589 Serial.println(""); 590 Serial.println(""); 591 } 592//-------------------------- end serial display function ------------------------- 593 594 595//**************************************************************************************************** 596//**************************************************************************************************** 597 598//--------------------------- Primary screen maps -------------------------------- 599/* 600******** 601updates needed 602******** 6031 ditch the contrast 6042 ditch the brightness 6053 setup screen timeout 606 607 608 609 610screen 0000 A)Home 611 screen 0001 a)settings 612 screen 0011 -brightness 613 screen 0011 -contrast 614 screen 0011 -screen lock time out 615 screen 0001 b)sensor monitors 616 screen 0021 -pir 617 screen 0121 *report pir detection 618 screen 0021 -sound 619 screen 0221 *sense alexa sound 620 screen 0221 *sense graves sound 621 screen 0221 *report mouth servo position 622 screen 0221 *adjust sensitivity? 623 screen 0021 -head potentiometer 624 screen 0021 -bluetooth 625 screen 0001 c)bluetooth 626 screen 0031 -on 627 screen 0031 -off 628 screen 0031 -monitor 629screen 0000 B)Mouth Control 630 screen 0002 a)test button 631 screen 0012 -open 632 screen 0012 -close 633 screen 0012 -push button chicken switch 634 screen 0002 b)sound sensors on/off 635 screen 0022 -alexa sense 636 screen 0122 *on 637 screen 0122 *off 638 screen 0122 *monitor sensor 639 screen 0022 -graves sense 640 screen 0222 *on 641 screen 0222 *off 642 screen 0222 *monitor sensors 643 screen 0002 c)sound sensor status 644 screen 0032 -alexa 645 screen 0032 -graves 646screen 0000 C)Head Control 647 screen 0003 a)pir on/off 648 screen 0013 -on 649 screen 0013 -off 650 screen 0013 -sensor 651 screen 0003 b)manual point 652 screen 0023 -slider 653*/ 654//**************************************************************************************************** 655//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 656//**************************************************************************************************** 657//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 658//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 659//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 660//**************************************************************************************************** 661//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 662//**************************************************************************************************** 663 664//-------------------------- begin callScreen function ------------------------- 665//-------------------------- begin callScreen function ------------------------- 666//-------------------------- begin callScreen function ------------------------- 667//-------------------------- begin callScreen function ------------------------- 668//-------------------------- begin callScreen function ------------------------- 669//-------------------------- begin callScreen function ------------------------- 670//-------------------------- begin callScreen function ------------------------- 671//-------------------------- begin callScreen function ------------------------- 672//-------------------------- begin callScreen function ------------------------- 673//-------------------------- begin callScreen function ------------------------- 674//-------------------------- begin callScreen function ------------------------- 675 676int callScreen(){ 677 Tft.fillRectangle(0, 0, 240, 320, BLACK); 678 679//<><><><><><><><><><><><><><><><><><><><><><><><> 680//<><><><><><><><> begin screen 0000 master <><><><><><><><> 681//<><><><><><><><><><><><><><><><><><><><><><><><> 682if(currentScreen == 0){ 683 // " " 684 Tft.drawString("GRAVES",0,5,4, GREEN); 685 Tft.drawString("INTERFACE",10,50,4,GREEN); 686 Tft.drawString("Home", 80,130, 3, GREEN); 687 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 688 Tft.drawString("Head Control", 10, 260, 3, GREEN); 689} 690//<><><><><><><><><><><><><><><><><><><><><><><><> 691//<><><><><><><><> end screen 0000 master <><><><><><><><><> 692//<><><><><><><><><><><><><><><><><><><><><><><><> 693 694//<><><><><><><><><><><><><><><><><><><><><><><><> 695//<><><><><><><><> begin screen 0001 <><><><><><><><> 696//<><><><><><><><><><><><><><><><><><><><><><><><> 697 if(currentScreen == 1){ 698 // " " 699 Tft.drawString("MEGA 2560",00,5,4,BLUE); 700 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 701 Tft.drawString("Settings", 10,130, 3, BLUE); 702 Tft.drawString("Sensors", 20, 195, 3, BLUE); 703 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 704 Tft.drawString("<", 0, 160, 3, GREEN); // back button 705} 706//<><><><><><><><><><><><><><><><><><><><><><><><> 707//<><><><><><><><> end screen 0001 <><><><><><><><><> 708//<><><><><><><><><><><><><><><><><><><><><><><><> 709 710//<><><><><><><><><><><><><><><><><><><><><><><><> 711//<><><><><><><><> begin screen 0011 <><><><><><><><> 712//<><><><><><><><><><><><><><><><><><><><><><><><> 713 if(currentScreen == 11){ 714 // " " 715 Tft.drawString("MEGA 2560",00,5,4,BLUE); 716 Tft.drawString("SETTINGS",10,50,4,YELLOW); 717 Tft.drawString("Brightness", 80,130, 3, BLUE); 718 Tft.drawString("Contrast", 05, 195, 3, GREEN); 719 Tft.drawString("Timeout", 10, 260, 3, GREEN); 720 Tft.drawString("<", 0, 160, 3, GREEN); // back button 721} 722 723//<><><><><><><><><><><><><><><><><><><><><><><><> 724//<><><><><><><><> end screen 0011 <><><><><><><><><> 725//<><><><><><><><><><><><><><><><><><><><><><><><> 726 727//<><><><><><><><><><><><><><><><><><><><><><><><> 728//<><><><><><><><> begin screen 0021 <><><><><><><><> 729//<><><><><><><><><><><><><><><><><><><><><><><><> 730 if(currentScreen == 21){ 731 // " " 732 Tft.drawString("MEGA 2560",00,5,4,BLUE); 733 Tft.drawString("SENSORS",10,50,4,YELLOW); 734 Tft.drawString("PIR Array", 80,130, 3, BLUE); 735 Tft.drawString("Sound", 05, 195, 3, GREEN); 736 Tft.drawString("Head Position", 10, 260, 3, GREEN); 737 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 738 Tft.drawString("<", 0, 160, 3, GREEN); // back button 739} 740//<><><><><><><><><><><><><><><><><><><><><><><><> 741//<><><><><><><><> end screen 0021 <><><><><><><><><> 742//<><><><><><><><><><><><><><><><><><><><><><><><> 743 744//<><><><><><><><><><><><><><><><><><><><><><><><> 745//<><><><><><><><> begin screen 0121 <><><><><><><><> 746//<><><><><><><><><><><><><><><><><><><><><><><><> 747 if(currentScreen == 121){ 748 // " " 749 Tft.drawString("PIR",0,5,4,BLUE); 750 Tft.drawString("ARRAY",10,50,4,YELLOW); 751 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 752 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 753 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 754 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 755 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 756 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 757 Tft.drawString("<", 0, 160, 3, GREEN); // back button 758} 759//<><><><><><><><><><><><><><><><><><><><><><><><> 760//<><><><><><><><> end screen 0121 <><><><><><><><><> 761//<><><><><><><><><><><><><><><><><><><><><><><><> 762 763//<><><><><><><><><><><><><><><><><><><><><><><><> 764//<><><><><><><><> begin screen 0221 <><><><><><><><> 765//<><><><><><><><><><><><><><><><><><><><><><><><> 766 if(currentScreen == 221){ 767 // " " 768 Tft.drawString("SOUND",0,5,4,BLUE); 769 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 770 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 771 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 772 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 773 Tft.drawString("<", 0, 160, 3, GREEN); // back button 774} 775//<><><><><><><><><><><><><><><><><><><><><><><><> 776//<><><><><><><><> end screen 0221 <><><><><><><><><> 777//<><><><><><><><><><><><><><><><><><><><><><><><> 778 779//<><><><><><><><><><><><><><><><><><><><><><><><> 780//<><><><><><><><> begin screen 0031 <><><><><><><><> 781//<><><><><><><><><><><><><><><><><><><><><><><><> 782 if(currentScreen == 31){ 783 // " " 784 Tft.drawString("Bluetooth",0,5,4,BLUE); 785 Tft.drawString("Control",10,50,4,YELLOW); 786 Tft.drawString("On", 80,130, 3, BLUE); 787 Tft.drawString("Off", 05, 195, 3, GREEN); 788 Tft.drawString("Monitor", 10, 260, 3, GREEN); 789 Tft.drawString("<", 0, 160, 3, GREEN); // back button 790} 791//<><><><><><><><><><><><><><><><><><><><><><><><> 792//<><><><><><><><> end screen 0031 <><><><><><><><><> 793//<><><><><><><><><><><><><><><><><><><><><><><><> 794 795//<><><><><><><><><><><><><><><><><><><><><><><><> 796//<><><><><><><><> begin screen 0002 <><><><><><><><> 797//<><><><><><><><><><><><><><><><><><><><><><><><> 798 if(currentScreen == 2){ 799 // " " 800 Tft.drawString("Mouth",0,5,4,BLUE); 801 Tft.drawString("Control",10,50,4,YELLOW); 802 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 803 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 804 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 805 Tft.drawString("<", 0, 160, 3, GREEN); // back button 806 } 807//<><><><><><><><><><><><><><><><><><><><><><><><> 808//<><><><><><><><> end screen 0002 <><><><><><><><><> 809//<><><><><><><><><><><><><><><><><><><><><><><><> 810 811 812//<><><><><><><><><><><><><><><><><><><><><><><><> 813//<><><><><><><><> begin screen 0012 <><><><><><><><> 814//<><><><><><><><><><><><><><><><><><><><><><><><> 815 if(currentScreen == 12){ 816 // " " 817 Tft.drawString("Jaw Test",0,5,4,BLUE); 818 Tft.drawString("Operations",10,50,4,YELLOW); 819 Tft.drawString("Open", 80,130, 3, BLUE); 820 Tft.drawString("Close", 05, 195, 3, GREEN); 821 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 822 Tft.drawString("<", 0, 160, 3, GREEN); // back button 823} 824//<><><><><><><><><><><><><><><><><><><><><><><><> 825//<><><><><><><><> end screen 0012 <><><><><><><><><> 826//<><><><><><><><><><><><><><><><><><><><><><><><> 827 828 829//<><><><><><><><><><><><><><><><><><><><><><><><> 830//<><><><><><><><> begin screen 0022 <><><><><><><><> 831//<><><><><><><><><><><><><><><><><><><><><><><><> 832 if(currentScreen == 22){ 833 // " " 834 Tft.drawString("Sound",0,5,4,BLUE); 835 Tft.drawString("Sensors",10,50,4,YELLOW); 836 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 837 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 838 Tft.drawString("Monitor", 10, 260, 3, GREEN); 839 Tft.drawString("<", 0, 160, 3, GREEN); // back button 840} 841//<><><><><><><><><><><><><><><><><><><><><><><><> 842//<><><><><><><><> end screen 0022 <><><><><><><><><> 843//<><><><><><><><><><><><><><><><><><><><><><><><> 844 845 846 847//<><><><><><><><><><><><><><><><><><><><><><><><> 848//<><><><><><><><> begin screen 0122 <><><><><><><><> 849//<><><><><><><><><><><><><><><><><><><><><><><><> 850 if(currentScreen == 122){ 851 // " " 852 Tft.drawString("Alexa Sense",0,5,4,BLUE); 853 Tft.drawString("Operations",10,50,4,YELLOW); 854 Tft.drawString("On", 120, 130, 3, GREEN); 855 Tft.drawString("Off", 115, 195, 3, RED); 856 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 857 Tft.drawString("<", 0, 160, 3, GREEN); // back button 858} 859//<><><><><><><><><><><><><><><><><><><><><><><><> 860//<><><><><><><><> end screen 0122 <><><><><><><><><> 861//<><><><><><><><><><><><><><><><><><><><><><><><> 862 863//<><><><><><><><><><><><><><><><><><><><><><><><> 864//<><><><><><><><> begin screen 0222 <><><><><><><><> 865//<><><><><><><><><><><><><><><><><><><><><><><><> 866 if(currentScreen == 222){ 867 // " " 868 Tft.drawString("Graves Sense",0,5,4,BLUE); 869 Tft.drawString("Operations",10,50,4,YELLOW); 870 Tft.drawString("On", 120, 130, 3, GREEN); 871 Tft.drawString("Off", 115, 195, 3, RED); 872 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 873 Tft.drawString("<", 0, 160, 3, GREEN); // back button 874} 875//<><><><><><><><><><><><><><><><><><><><><><><><> 876//<><><><><><><><> end screen 0222 <><><><><><><><><> 877//<><><><><><><><><><><><><><><><><><><><><><><><> 878 879//<><><><><><><><><><><><><><><><><><><><><><><><> 880//<><><><><><><><> begin screen 0032 <><><><><><><><> 881//<><><><><><><><><><><><><><><><><><><><><><><><> 882 if(currentScreen == 32){ 883 // " " 884 Tft.drawString("Sound Sense",0,5,4,BLUE); 885 Tft.drawString("Monitors",10,50,4,YELLOW); 886 Tft.drawString("Alexa", 80,130, 3, BLUE); 887 Tft.drawString("Graves", 05, 195, 3, GREEN); 888 Tft.drawString("<", 0, 160, 3, GREEN); // back button 889} 890//<><><><><><><><><><><><><><><><><><><><><><><><> 891//<><><><><><><><> end screen 0032 <><><><><><><><><> 892//<><><><><><><><><><><><><><><><><><><><><><><><> 893 894//<><><><><><><><><><><><><><><><><><><><><><><><> 895//<><><><><><><><> begin screen 0003 <><><><><><><><> 896//<><><><><><><><><><><><><><><><><><><><><><><><> 897 if(currentScreen == 3){ 898 // " " 899 Tft.drawString("Head Control",0,5,4,BLUE); 900 Tft.drawString("Operations",10,50,4,YELLOW); 901 Tft.drawString("PIR Array", 80,130, 3, BLUE); 902 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 903 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 904 Tft.drawString("<", 0, 160, 3, GREEN); // back button 905} 906//<><><><><><><><><><><><><><><><><><><><><><><><> 907//<><><><><><><><> end screen 0003 <><><><><><><><><> 908//<><><><><><><><><><><><><><><><><><><><><><><><> 909 910//<><><><><><><><><><><><><><><><><><><><><><><><> 911//<><><><><><><><> begin screen 0013 <><><><><><><><> 912//<><><><><><><><><><><><><><><><><><><><><><><><> 913 if(currentScreen == 13){ 914 // " " 915 Tft.drawString("PIR Control",0,5,4,BLUE); 916 Tft.drawString("Operations",10,50,4,YELLOW); 917 Tft.drawString("On", 80,130, 3, BLUE); 918 Tft.drawString("Off", 05, 195, 3, GREEN); 919 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 920 Tft.drawString("<", 0, 160, 3, GREEN); // back button 921} 922//<><><><><><><><><><><><><><><><><><><><><><><><> 923//<><><><><><><><> end screen 0013 <><><><><><><><><> 924//<><><><><><><><><><><><><><><><><><><><><><><><> 925 926//<><><><><><><><><><><><><><><><><><><><><><><><> 927//<><><><><><><><> begin screen 0023 <><><><><><><><> 928//<><><><><><><><><><><><><><><><><><><><><><><><> 929 if(currentScreen == 23){ 930 // " " 931 Tft.drawString("Graves Head",0,5,3,BLUE); 932 Tft.drawString("Operations",10,50,3,YELLOW); 933 Tft.drawString("On", 120, 130, 3, GREEN); 934 Tft.drawString("Off", 115, 195, 3, RED); 935// Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 936 Tft.drawString("<", 0, 160, 3, GREEN); // back button 937} 938//<><><><><><><><><><><><><><><><><><><><><><><><> 939//<><><><><><><><> end screen 0023 <><><><><><><><><> 940//<><><><><><><><><><><><><><><><><><><><><><><><> 941 942 943//<><><><><><><><><><><><><><><><><><><><><><><><> 944//<><><><><><><><> begin screen 0422 <><><><><><><><> 945//<><><><><><><><><><><><><><><><><><><><><><><><> 946 if(currentScreen == 422){ 947 // " " 948 Tft.drawString("Command Sent",0,5,3,BLUE); 949 Tft.drawString("Press Back to",0,55,3,YELLOW); 950 Tft.drawString("Contiue", 50,105, 3, BLUE); 951 Tft.drawString("<", 0, 160, 3, GREEN); // back button 952} 953//<><><><><><><><><><><><><><><><><><><><><><><><> 954//<><><><><><><><> end screen 0422 <><><><><><><><><> 955//<><><><><><><><><><><><><><><><><><><><><><><><> 956 957 958////<><><><><><><><><><><><><><><><><><><><><><><><> 959////<><><><><><><><> begin screen lost <><><><><><><><> 960////<><><><><><><><><><><><><><><><><><><><><><><><> 961// else if(currentScreen){ 962// // " " 963// Tft.drawString("Screen not",0,5,3,BLUE); 964// Tft.drawString("found. Please",40,50,3,YELLOW); 965// Tft.drawString("use the back", 80,130, 3, BLUE); 966// Tft.drawString("button to", 05, 195, 3, GREEN); 967// Tft.drawString("return to fun", 10, 260, 3, GREEN); 968// Tft.drawString("<", 0, 160, 3, GREEN); // back button 969//} 970////<><><><><><><><><><><><><><><><><><><><><><><><> 971////<><><><><><><><> end screen lost <><><><><><><><><> 972////<><><><><><><><><><><><><><><><><><><><><><><><> 973 974}// callScreen 975//-------------------------- end callScreen function ------------------------- 976//-------------------------- end callScreen function ------------------------- 977//-------------------------- end callScreen function ------------------------- 978//-------------------------- end callScreen function ------------------------- 979//-------------------------- end callScreen function ------------------------- 980//-------------------------- end callScreen function ------------------------- 981//-------------------------- end callScreen function ------------------------- 982//-------------------------- end callScreen function ------------------------- 983//-------------------------- end callScreen function ------------------------- 984//-------------------------- end callScreen function ------------------------- 985//-------------------------- end callScreen function ------------------------- 986//-------------------------- end callScreen function ------------------------- 987//-------------------------- end callScreen function ------------------------- 988 989 990//**************************************************************************************************** 991//**************************************************************************************************** 992 993 994 995 996 997 998 999//**************************************************************************************************** 1000//**************************************************************************************************** 1001 1002// fin
22102018 graves uno head code late night
c_cpp
head is tracking better. head on off function control from tft is successful! added ramped speeds to motor control. mostly debugged. needs a trim. could talk a bit more and use its outgoing skills.
1/* 222102018 3 4gravesunohead 5 6graves project 7arduino 8 Uno 9Slave 2 10coded from scratch by wylie jones 11wyliejones@gmail.com 12 13Graves 14 multi arduino build 10/2018 15Arduino mega 2560 with 240/320 tft and micro sd card 16 (for storing screen backgrounds) 17two arduino uno's 18slave1 arduino uno to sense 19 sound from graves and echo dot to control mouth 20slave2 arduino uno to control 21 passive sensor array and head servo 22 23Graves' head originally had a motor to 24 look left and right. The routine failed; so, the built in 25routine was scrapped 26 in favor of a L298n motor controller coupled through the arduino to a pir 27array 28 added to the serving tray. The result is a passive tracking abilty to 29face the 30 skull towards the direction of the triggered sensor. CREEPY. 31 32the pir sensors 33 are hc-sr501 type passive infrared recievers with their bug-eye lenses removed 34I 35 bypassed R13 and R33 on all 5 sensors to decrease the hadwired delay. 36 37the 38 sensors need the addition of a pull-down reisistor circuit. The sensors send voltage 39 to the pin 40on the arduino when something is detected. When nothing is detected 41 and the pins are left to float, 42the system glitches with multiple false triggers. 43 Thus, a pull down resistor is needed for every sensor 44to ensure the state read 45 is a 0. 46 47 48signal in from pir signal continues 49 to arduino digital pin 50--------------------*----------------------------------------- 51 52 \\ 53 tap into signal wire \\ 54 \\ 55 10k Ohm 56 \ resistor to ground 57 (all bundled together to ground) 58 *-------/\\/\\/------------------------ 59 60 61*/ 62 63 64// 65 L298n motor controller code 66// connect motor controller pins to Arduino digital 67 pins 68// motor one 69int enA = 10; 70int in1 = 8; 71int in2 = 9; 72// L298n 73 motor controller code 74 75// pot switches 76int potControlPin = A1; // analog 77 pin used to connect the controller potentiometer 78//int valControl; // variable 79 to read the value from the analog pin for control input 80int potControl = 0; // 81 variable to store the servo position from the controller pot switch 82int potPositionPin 83 = A0; // analog pin used to connect the position monitoring potentiometer 84int 85 valPosition; // variable to read the value from the analog pin connected to position 86 monitor 87int potPosition = 0; // variable to store the servo position of the 88 monitoring pot switch 89// pot switches 90int detectedPosition; // variable to 91 store info 92boolean pirStatus; 93 94int servangle = 0; // servo angle variable 95int 96 pirNo[] = {3,4,5,6,7}; // pir pin numbers 97int pirPrevLow[] = {1,1,1,1,1}; 98 // previously low flag set to true 99int pirPrevUsed[] = {0,0,0,0,0}; // 100 has pir been on used before going low 101unsigned long pirPrevMillis[] = {0,0,0,0,0}; 102 // has pir been on used before going low 103unsigned long pirCurMillis[] = 104 {0,0,0,0,0}; // has pir been on used before going low 105int pirPos[] = {10,60,100,140,170}; 106 // positions for servo (0-180) 107int curPosPir = 0; 108int pirPin = 3; 109int 110 senseState3; 111int senseState4; 112int senseState5; 113int senseState6; 114int 115 senseState7; 116 117 unsigned long currentMillis; 118unsigned long time; 119long 120 ignoreTime; 121// for blinking 122const int ledPin = LED_BUILTIN;// the number 123 of the LED pin 124int ledState = LOW; // ledState used to set the LED 125unsigned 126 long previousMillis = 0; // will store last time LED was updated 127 128long 129 interval = 1; // interval at which to move servos (milliseconds) 130 131char 132 incomingHeadByte; 133char outgoingHeadByte; 134int headOnOffAdjusted; 135int headOnOffOld; 136int 137 headOnOffNew; 138 139 140void setup() { 141 delay(500); 142 Serial.begin(9600); 143 144 incomingHeadByte = 0; // for incoming serial data 145 outgoingHeadByte = 0; // 146 for a bit more talkative serial data 147 headOnOffAdjusted = 1; 148 headOnOffOld 149 = 1; // stores head state from serial connection 150 headOnOffNew = 1; // stores 151 head state from serial connection 152 153 154 time = millis(); 155 // motor control 156 setup code 157 // set all the motor control pins to outputs 158 pinMode(enA, OUTPUT); 159 160 pinMode(in1, OUTPUT); 161 pinMode(in2, OUTPUT); 162 // motor control setup code 163 164 pinMode(LED_BUILTIN, OUTPUT); 165 pinMode(pirNo[3], INPUT); 166 pinMode(pirNo[4], 167 INPUT); 168 pinMode(pirNo[5], INPUT); 169 pinMode(pirNo[6], INPUT); 170 pinMode(pirNo[7], 171 INPUT); 172 173 // blink led to denote ready 174 blinkSlow(); 175} 176//---------------------end 177 void setup----------------------- 178//---------------------end void setup----------------------- 179//---------------------end 180 void setup----------------------- 181 182//---------------------begin void loop----------------------- 183//---------------------begin 184 void loop----------------------- 185//---------------------begin void loop----------------------- 186 187void 188 loop(){ 189 serialDoStuff(); 190 if(headOnOffNew == headOnOffOld){ 191 if(headOnOffNew 192 == 1){ 193 sensePositionFunction(); 194 headTurn(); 195 pirReport(); 196 197 } 198 if(headOnOffNew == 2){ 199 previousMillis = currentMillis; 200 201 // do Thing C 202 // turn motor off 203 analogWrite(enA, 0); 204 digitalWrite(in1, 205 LOW); 206 digitalWrite(in2, LOW); 207 outgoingHeadByte = '-'; 208 Serial.write(outgoingHeadByte); 209 210 Serial.println(""); 211 } 212 } 213 else if(headOnOffNew != headOnOffOld){ 214 215 headOnOffNew = headOnOffOld; 216 } 217} 218 219//---------------------end 220 void loop----------------------- 221//---------------------end void loop----------------------- 222//---------------------end 223 void loop----------------------- 224 225 226//********************************************************* 227//********************************************************* 228 229//---------------------begin 230 serialDoStuff ----------------- 231void serialDoStuff(){ 232 if(Serial.available() 233 > 0){ 234 incomingHeadByte = Serial.read(); 235 headOnOffAdjusted = incomingHeadByte 236 - '0'; 237 if(headOnOffAdjusted == 1){ 238 Serial.flush(); 239// outgoingHeadByte 240 = 1; 241// Serial.write(outgoingHeadByte); 242 headOnOffOld = 1; 243 } 244 245 else if(headOnOffAdjusted == 2){ 246 Serial.flush(); 247// outgoingHeadByte 248 = 2; 249// Serial.write(outgoingHeadByte); 250 headOnOffOld = 2; 251 } 252 253 } 254} 255//---------------------end serialDoStuff----------------- 256 257//********************************************************* 258//********************************************************* 259//********************************************************* 260//********************************************************* 261// 262 ++++++++++++++++++begin PIR function +++++++++++++++++++++++++++++++ 263 264void 265 sensePositionFunction(){ 266 ignoreTime = 4000; 267 for(int j=0;j<5;j++){ // do 268 this for each PIR in the array 269 pirPin=pirNo[j]; 270 pirCurMillis[j] = 271 millis(); 272 pirStatus = digitalRead(pirPin); 273 if(pirStatus == HIGH){ 274 // while cycling through the array if pirNo[j] is HIGH, do this 275 if(pirPrevLow[j]){ 276 // and If pirNo[j] was previously low, do this 277 if(curPosPir != pirPin 278 && pirPrevUsed[j] == 0){ // if pirNo[j] is HIGH and different than curPosPir, move 279 to new position 280 curPosPir = pirPin; // keep current PIR 281 pirPrevUsed[j] 282 = 1; 283 if(ignoreTime > pirCurMillis[j] - pirPrevMillis[j]){ // example 284 4 sec > 30 sec - 28 sec 285 Serial.print(" pin 286 skipped for being too early "); 287 Serial.println(curPosPir); 288 } 289 290 else if(ignoreTime <= pirCurMillis[j] - pirPrevMillis[j]){ // example 291 4 sec < 38 sec - 32 sec 292 detectedPosition = pirPin; 293 pirPrevMillis[j] 294 = millis(); 295 } 296// return detectedPosition; 297 } 298 299 pirPrevLow[j] = 0; // pir is now recorded as not low 300 } 301 } 302 303 else{ 304 pirPrevLow[j] = 1; // pir is now recorded as low 305 pirPrevUsed[j] 306 = 0; 307 } 308 } // end j number of pirs loop 309Serial.print(" detectedPosition 310 "); 311Serial.println(detectedPosition); 312} 313//+++++++++++++++++++++++end PIR 314 function +++++++++++++++++++++++++++++++ 315void pirReport(){ 316 senseState3 317 = digitalRead(3); 318 319// Serial.println(millis()/1000); 320 Serial.print(" 321 3"); 322 Serial.print(senseState3); 323 324 325 326 delay(5); 327 senseState4 = digitalRead(4); 328 329// 330 Serial.println(millis()/1000); 331 Serial.print(" 4"); 332 Serial.print(senseState4); 333 334 335 336 senseState5 = digitalRead(5); 337 338// Serial.println(millis()/1000); 339 340 Serial.print(" 5"); 341 Serial.print(senseState5); 342 343 344 345 senseState6 = digitalRead(6); 346 347// Serial.println(millis()/1000); 348 349 Serial.print(" 6"); 350 Serial.print(senseState6); 351 352 353 354 senseState7 = digitalRead(7); 355 356// Serial.println(millis()/1000); 357 358 Serial.print(" 7"); 359 Serial.print(senseState7); 360 361 362 363 // delay(5); 364//clear screen 365 Serial.println(""); 366// Serial.println(""); 367// 368 Serial.println(""); 369// Serial.println(""); 370// Serial.println(""); 371// 372 Serial.println(""); 373// Serial.println(""); 374// 375// delay(50); 376 377 } 378//********************************************************* 379//********************************************************* 380 381//---------------------begin 382 headTurn ------------------- 383 384void headTurn() { 385currentMillis = millis(); 386 387 388 long motorStep = 50; // time for motor to run before switching off 389 390 // begin 391 potservo section for potentiometer control 392// int valControl = analogRead(A0); 393 // reads the value of the potentiometer (value between 0 and 1023) 394// 395 valControl = map(valControl, 0, 1023, 0, 10); // first set refers to pot min/max 396 second is servo map 397 int valControl = detectedPosition; // reads 398 the value of the potentiometer (value between 0 and 1023) 399 valControl = map(valControl, 400 7, 3, 1, 5); // first number set refers to pir array pins, second is servo map 401 402 int valPosition = analogRead(A0); // reads value of position pot 403 valPosition 404 = map(valPosition, 350, 650, 5, 1); // first min second max read from position 405 potentiometer 406// Serial.print("control "); 407// Serial.println(valControl); 408 409 Serial.print(" valControl "); 410 Serial.println(valControl); 411 Serial.print(" 412 reported position "); 413 Serial.println(valPosition); 414 Serial.print(" 415 position "); 416 Serial.println(analogRead(A1)); 417// 418 Serial.print(" raw pot pos "); 419// Serial.println(analogRead(A0)); 420 421 if (valPosition > valControl + 3){ // new position is far 422 if(currentMillis 423 - previousMillis > interval){ 424 previousMillis = currentMillis; 425 // 426 set speed to __ out of possible range 80~255 427 analogWrite(enA, 140); 428 429 digitalWrite(in1, HIGH); 430 digitalWrite(in2, LOW); 431// delay(200); 432// 433 digitalWrite(in1, LOW); 434 outgoingHeadByte = '<<<'; 435 Serial.write(outgoingHeadByte); 436 437 Serial.println(""); 438 } 439 } 440 else if(valPosition < valControl 441 - 3){ // new position is far 442 if(currentMillis - previousMillis > interval) 443 { 444 previousMillis = currentMillis; 445 // do Thing B 446 // turn 447 on motor A backward 448 // set speed to __ out of possible range 80~255 449 450 analogWrite(enA, 140); 451 digitalWrite(in1, LOW); 452 digitalWrite(in2, 453 HIGH); 454// delay(200); 455// digitalWrite(in2, LOW); 456 outgoingHeadByte 457 = '>>>'; 458 Serial.write(outgoingHeadByte); 459 Serial.println(""); 460 461 } 462 } 463 else if (valPosition == valControl + 2){ // new position is getting 464 close 465 if(currentMillis - previousMillis > interval){ 466 previousMillis 467 = currentMillis; 468 // set speed to __ out of possible range 80~255 469 analogWrite(enA, 470 100); 471 digitalWrite(in1, HIGH); 472 digitalWrite(in2, LOW); 473// delay(100); 474// 475 digitalWrite(in1, LOW); 476 outgoingHeadByte = '<<'; 477 Serial.write(outgoingHeadByte); 478 479 Serial.println(""); 480 } 481 } 482 else if(valPosition == valControl 483 - 2){ // new position is getting close 484 if(currentMillis - previousMillis 485 > interval) { 486 previousMillis = currentMillis; 487 // do Thing B 488 489 // turn on motor A backward 490 // set speed to __ out of possible range 491 80~255 492 analogWrite(enA, 100); 493 digitalWrite(in1, LOW); 494 digitalWrite(in2, 495 HIGH); 496// delay(100); 497// digitalWrite(in2, LOW); 498 outgoingHeadByte 499 = '>>'; 500 Serial.write(outgoingHeadByte); 501 Serial.println(""); 502 503 } 504 } 505 else if (valPosition == valControl + 1){ // new position is next 506 over 507 if(currentMillis - previousMillis > interval){ 508 previousMillis 509 = currentMillis; 510 // set speed to __ out of possible range 80~255 511 analogWrite(enA, 512 85); 513 digitalWrite(in1, HIGH); 514 digitalWrite(in2, LOW); 515// delay(100); 516// 517 digitalWrite(in1, LOW); 518 outgoingHeadByte = '<'; 519 Serial.write(outgoingHeadByte); 520 521 Serial.println(""); 522 } 523 } 524 else if(valPosition == valControl 525 - 1){ // new position is next over 526 if(currentMillis - previousMillis > interval) 527 { 528 previousMillis = currentMillis; 529 // do Thing B 530 // turn 531 on motor A backward 532 // set speed to __ out of possible range 80~255 533 534 analogWrite(enA, 85); 535 digitalWrite(in1, LOW); 536 digitalWrite(in2, 537 HIGH); 538// delay(100); 539// digitalWrite(in2, LOW); 540 outgoingHeadByte 541 = '>'; 542 Serial.write(outgoingHeadByte); 543 Serial.println(""); 544 545 } 546 } 547 else 548 { 549 previousMillis = currentMillis; 550 // do 551 Thing C 552 // turn motor off 553 analogWrite(enA, 0); 554 digitalWrite(in1, 555 LOW); 556 digitalWrite(in2, LOW); 557 outgoingHeadByte = '-'; 558 Serial.write(outgoingHeadByte); 559 560 Serial.println(""); 561 } 562} 563//---------------------end headTurn-------------------- 564//********************************************************* 565//********************************************************* 566//---------------------begin 567 blink slow------------------- 568void blinkSlow(){ 569unsigned long currentMillis 570 = millis(); 571const long interval1 = 500; 572 573 if(currentMillis - previousMillis 574 >= interval1) { 575 previousMillis = currentMillis; 576 if(ledState == LOW){ 577 578 ledState = HIGH; 579 } 580 else{ 581 ledState = LOW; 582 } 583 584 digitalWrite(ledPin, ledState); 585 } 586} 587//---------------------end blink 588 slow------------------- 589//---------------------begin blink fast ------------------- 590void 591 blinkFast(){ 592unsigned long currentMillis = millis(); 593const long interval2 594 = 75; 595 if(currentMillis - previousMillis >= interval2){ 596 previousMillis 597 = currentMillis; 598 if(ledState == LOW){ 599 ledState = HIGH; 600 } 601 602 else{ 603 ledState = LOW; 604 } 605 digitalWrite(ledPin, ledState); 606 607 } 608} 609//---------------------end blink fast ------------------- 610
draft 12102018
c_cpp
latest update finished sorting out page navigation need to clean up colors and word positions will fill in data fetch later
1/* 2last edit sun oct 12 2018 3coded from scratch by wylie jones 4wyliejones@gmail.com 5 6Graves multi arduino build 10/2018 7Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 8two arduino uno's 9slave1 arduino uno to sense sound from graves and echo dot to control mouth 10slave2 arduino uno to control passive sensor array and head servo 11 12sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 13 14 analogue pin speaker + 15 \ / (red from speaker) 16 \ / 17 \ / 18 *--------[=]-----------*---------[=]----------* 19 | resistor \ resistor | 20 | \ | 21 |(red with white) \ |to arduino ground (black with white) 22to arduino 5v+ speaker - 23 (black from speaker) 24 25*/ 26//end notes 27//end notes 28//end notes 29//end notes 30//end notes 31//end notes 32 33 34//********************************************************* 35//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 36//********************************************************* 37 38 39//begin declarations 40//begin declarations 41//begin declarations 42//begin declarations 43//begin declarations 44//begin declarations 45//begin declarations 46 47//#include <TFT.h> 48//#include <Servo.h> 49//#include <stdint.h> 50//#include <SD.h> 51#include <TFTv2.h> 52#include <SPI.h> 53#include <SeeedTouchScreen.h> 54 55//const int PIN_SD_CS = 4; // pin of sd card 56 57TouchScreen ts = TouchScreen(XP, YP, XM, YM); 58int buttonPressed; // stores which button was pressed 59int newButtonTime; // debounce 60int oldButtonTime; // debounce 61int buttonTimeDifference; // debounce 62int debounceTime; // debounce 63int currentScreen; // identifies current screen by adding x y and z 64int zMax = 460; // maximum pressure to detect 65int zMin = 100; // minimum pressure to detect 66int x; // for ones 67int y; // for tens 68int z; // for hundreds 69//end declarations 70//end declarations 71//end declarations 72//end declarations 73//end declarations 74//end declarations 75//end declarations 76//end declarations 77//end declarations 78 79//********************************************************* 80//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 81//********************************************************* 82 83// begin void setup 84// begin void setup 85// begin void setup 86// begin void setup 87// begin void setup 88// begin void setup 89// begin void setup 90// begin void setup 91// begin void setup 92// begin void setup 93// begin void setup 94void setup() { 95Serial.begin(115200); 96 oldButtonTime = millis(); 97 Tft.TFTinit(); // init TFT library 98 TFT_BL_ON; // turn on the background light 99 x = 0; 100 y = 0; 101 z = 0; 102 buttonPressed = 4; 103 debounceTime = 1000; // button debounce in milliseconds 104 currentScreen = 0; 105 callScreen(); 106 107} //void setup() 108// end void setup 109// end void setup 110// end void setup 111// end void setup 112// end void setup 113// end void setup 114// end void setup 115// end void setup 116 117//********************************************************* 118//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 119//********************************************************* 120 121// begin void loop 122// begin void loop 123// begin void loop 124// begin void loop 125// begin void loop 126// begin void loop 127// begin void loop 128// begin void loop 129// begin void loop 130// begin void loop 131// begin void loop 132// begin void loop 133// begin void loop 134// begin void loop 135 136void loop() { 137 tftDetect(); // gather information from touch screen touches 138 buttonTimeDifference = newButtonTime - oldButtonTime; 139 if(debounceTime < buttonTimeDifference){ 140 whatScreen(); 141 callScreen(); 142 oldButtonTime = newButtonTime; 143 showStuff(); // serial prints 144 tftDisplay(); // display x y coordinates on tft display 145 } 146} //void loop() 147 148// end of void loop 149// end of void loop 150// end of void loop 151// end of void loop 152// end of void loop 153// end of void loop 154// end of void loop 155// end of void loop 156// end of void loop 157// end of void loop 158// end of void loop 159// end of void loop 160// end of void loop 161// end of void loop 162// end of void loop 163 164//**************************************************************************************************** 165//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 166//**************************************************************************************************** 167///////////////////////////////////////////////////////////////////////////////////////////////////////// 168///////////////////////////////////////// functions /////////////////////////////////////////////////// 169///////////////////////////////////////////////////////////////////////////////////////////////////////// 170//**************************************************************************************************** 171//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 172//**************************************************************************************************** 173 174//--------------------------begin tftDetect---------------------------------- 175//--------------------------begin tftDetect---------------------------------- 176//--------------------------begin tftDetect---------------------------------- 177//--------------------------begin tftDetect---------------------------------- 178//--------------------------begin tftDetect---------------------------------- 179int tftDetect(){ 180 Point p = ts.getPoint(); 181 if(zMin<p.z && p.z<zMax){ 182 newButtonTime = millis(); 183 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 184 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 185//Button 1 186 if(75<p.x && p.x<140){ 187 if(100<p.y && p.y<164){ 188 buttonPressed = 1; 189 } 190//Button 2 191 if(164<p.y && p.y<240){ 192 buttonPressed = 2; 193 } 194//Button 3 195 if(240<p.y && p.y<310){ 196 buttonPressed = 3; 197 } 198 } 199 } 200//Button 4 201 if(10<p.x && p.x<75){ 202 if(100<p.y && p.y<240){ 203 buttonPressed = 4; 204 } 205 } 206}//void tftDetect 207//--------------------------end tftDetect code---------------------------------- 208//--------------------------end tftDetect code---------------------------------- 209//--------------------------end tftDetect code---------------------------------- 210//--------------------------end tftDetect code---------------------------------- 211//--------------------------end tftDetect code---------------------------------- 212//**************************************************************************************************** 213//**************************************************************************************************** 214//-------------------------- begin whatScreen function ------------------------- 215//-------------------------- begin whatScreen function ------------------------- 216//-------------------------- begin whatScreen function ------------------------- 217//-------------------------- begin whatScreen function ------------------------- 218 219int whatScreen(){ 220 if(x == 0){ 221 if(buttonPressed == 1){ 222 x = x + 1; 223 Serial.println("x + 1"); 224 } 225 if(buttonPressed == 2){ 226 x = x + 2; 227 Serial.println("x + 2"); 228 } 229 if(buttonPressed == 3){ 230 x = x + 3; 231 Serial.println("x + 3"); 232 } 233 if(buttonPressed == 4){ 234 x = 0; 235 Serial.println("x = 0"); 236 } 237 } 238 else if(x >> 0){ 239 if(y == 0){ 240 if(buttonPressed == 1){ 241 y = y + 10; 242 Serial.println("y + 10"); 243 } 244 if(buttonPressed == 2){ 245 y = y + 20; 246 Serial.println("y + 20"); 247 } 248 if(buttonPressed == 3){ 249 y = y + 30; 250 Serial.println("y + 30"); 251 } 252 if(buttonPressed == 4){ 253 x = 0; 254 Serial.println("x = 0"); 255 } 256 } 257 else if (y >> 0){ 258 if(buttonPressed == 1){ 259 z = z + 100; 260 Serial.println("z + 100"); 261 } 262 if(buttonPressed == 2){ 263 z = z + 200; 264 Serial.println("z + 200"); 265 } 266 if(buttonPressed == 3){ 267 z = z + 300; 268 Serial.println("z + 300"); 269 } 270 if(buttonPressed == 4){ 271 if(z == 0){ 272 y = 0; 273 Serial.println("y = 0"); 274 } 275 else if(z >> 0){ 276 z = 0; 277 Serial.println("z = 0"); 278 } 279 } 280 }//y>0 281 }//x>0 282 currentScreen = z+y+x; 283} 284//-------------------------- end whatScreen function ------------------------- 285//-------------------------- end whatScreen function ------------------------- 286//-------------------------- end whatScreen function ------------------------- 287//-------------------------- end whatScreen function ------------------------- 288//-------------------------- end whatScreen function ------------------------- 289 290//**************************************************************************************************** 291//**************************************************************************************************** 292 293//--------------------------begin arduino master data fetch calls---------------------------------- 294// call slave1 arduino for data 295// call slave2 arduino for data 296//--------------------------end arduino master data fetch calls------------------------------------ 297 298//**************************************************************************************************** 299//**************************************************************************************************** 300 301//--------------------------begin tftDisplay code---------------------------------- 302void tftDisplay(){ 303 Point p = ts.getPoint(); 304 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 305 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 306 Tft.fillRectangle(0, 160, 60, 30, BLACK); 307 Tft.drawNumber((p.x), 0, 160, 3, GREEN); 308 Tft.fillRectangle(180, 160, 60, 30, BLACK); 309 Tft.drawNumber((p.y), 180, 160, 3, GREEN); 310 Tft.fillRectangle(80, 160, 60, 30, BLACK); 311 Tft.drawNumber((buttonPressed), 80, 160, 3, GREEN); 312}// void tftDisplay 313//--------------------------end tftDisplay code------------------------------------ 314 315//**************************************************************************************************** 316//**************************************************************************************************** 317 318//-------------------------- begin slave1 data fetch function -------------------------- 319//-------------------------- end slave1 data fetch function -------------------------- 320 321//**************************************************************************************************** 322//**************************************************************************************************** 323 324//-------------------------- begin slave2 data fetch function -------------------------- 325//-------------------------- end slave2 data fetch function ------------------------- 326 327//**************************************************************************************************** 328//**************************************************************************************************** 329 330//-------------------------- begin serial display function -------------------------- 331void showStuff(){ 332 Serial.println("------/ last update /-------"); 333// Serial.println("------begin display-------"); 334 Serial.print("buttonPressed "); 335 Serial.println(buttonPressed); 336 Serial.print("x "); 337 Serial.println(x); 338 Serial.print("y "); 339 Serial.println(y); 340 Serial.print("z "); 341 Serial.println(z); 342 Serial.print("currentScreen "); 343 Serial.println(currentScreen); 344// Serial.println("-------end display--------"); 345 Serial.println(""); 346 Serial.println(""); 347 Serial.println(""); 348 } 349//-------------------------- end serial display function ------------------------- 350 351 352//**************************************************************************************************** 353//**************************************************************************************************** 354 355//--------------------------- Primary screen maps -------------------------------- 356/* 357 358screen 0000 A)Home 359 screen 0001 a)settings 360 screen 0011 -brightness 361 screen 0011 -contrast 362 screen 0011 -screen lock time out 363 screen 0001 b)sensor monitors 364 screen 0021 -pir 365 screen 0121 *report pir detection 366 screen 0021 -sound 367 screen 0221 *sense alexa sound 368 screen 0221 *sense graves sound 369 screen 0221 *report mouth servo position 370 screen 0221 *adjust sensitivity? 371 screen 0021 -head potentiometer 372 screen 0021 -bluetooth 373 screen 0001 c)bluetooth 374 screen 0031 -on 375 screen 0031 -off 376 screen 0031 -monitor 377screen 0000 B)Mouth Control 378 screen 0002 a)test button 379 screen 0012 -open 380 screen 0012 -close 381 screen 0012 -push button chicken switch 382 screen 0002 b)sound sensors on/off 383 screen 0022 -alexa sense 384 screen 0122 *on 385 screen 0122 *off 386 screen 0122 *monitor sensor 387 screen 0022 -graves sense 388 screen 0222 *on 389 screen 0222 *off 390 screen 0222 *monitor sensors 391 screen 0002 c)sound sensor status 392 screen 0032 -alexa 393 screen 0032 -graves 394screen 0000 C)Head Control 395 screen 0003 a)pir on/off 396 screen 0013 -on 397 screen 0013 -off 398 screen 0013 -sensor 399 screen 0003 b)manual point 400 screen 0023 -slider 401*/ 402//**************************************************************************************************** 403//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 404//**************************************************************************************************** 405//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 406//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 407//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 408//**************************************************************************************************** 409//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 410//**************************************************************************************************** 411 412//-------------------------- begin callScreen function ------------------------- 413//-------------------------- begin callScreen function ------------------------- 414//-------------------------- begin callScreen function ------------------------- 415//-------------------------- begin callScreen function ------------------------- 416//-------------------------- begin callScreen function ------------------------- 417//-------------------------- begin callScreen function ------------------------- 418//-------------------------- begin callScreen function ------------------------- 419//-------------------------- begin callScreen function ------------------------- 420//-------------------------- begin callScreen function ------------------------- 421//-------------------------- begin callScreen function ------------------------- 422//-------------------------- begin callScreen function ------------------------- 423 424int callScreen(){ 425 Tft.fillRectangle(0, 0, 240, 320, BLACK); 426 427//<><><><><><><><><><><><><><><><><><><><><><><><> 428//<><><><><><><><> begin screen 0000 master <><><><><><><><> 429//<><><><><><><><><><><><><><><><><><><><><><><><> 430if(currentScreen == 0){ 431 // " " 432 Tft.drawString("GRAVES",0,5,4, GREEN); 433 Tft.drawString("INTERFACE",10,50,4,GREEN); 434 Tft.drawString("Home", 80,130, 3, GREEN); 435 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 436 Tft.drawString("Head Control", 10, 260, 3, GREEN); 437} 438//<><><><><><><><><><><><><><><><><><><><><><><><> 439//<><><><><><><><> end screen 0000 master <><><><><><><><><> 440//<><><><><><><><><><><><><><><><><><><><><><><><> 441 442//<><><><><><><><><><><><><><><><><><><><><><><><> 443//<><><><><><><><> begin screen 0001 <><><><><><><><> 444//<><><><><><><><><><><><><><><><><><><><><><><><> 445 if(currentScreen == 1){ 446 // " " 447 Tft.drawString("MEGA 2560",00,5,4,BLUE); 448 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 449 Tft.drawString("Settings", 10,130, 3, BLUE); 450 Tft.drawString("Sensors", 20, 195, 3, BLUE); 451 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 452 Tft.drawString("<", 0, 160, 3, GREEN); // back button 453} 454//<><><><><><><><><><><><><><><><><><><><><><><><> 455//<><><><><><><><> end screen 0001 <><><><><><><><><> 456//<><><><><><><><><><><><><><><><><><><><><><><><> 457 458//<><><><><><><><><><><><><><><><><><><><><><><><> 459//<><><><><><><><> begin screen 0011 <><><><><><><><> 460//<><><><><><><><><><><><><><><><><><><><><><><><> 461 if(currentScreen == 11){ 462 // " " 463 Tft.drawString("MEGA 2560",00,5,4,BLUE); 464 Tft.drawString("SETTINGS",10,50,4,YELLOW); 465 Tft.drawString("Brightness", 80,130, 3, BLUE); 466 Tft.drawString("Contrast", 05, 195, 3, GREEN); 467 Tft.drawString("Timeout", 10, 260, 3, GREEN); 468 Tft.drawString("<", 0, 160, 3, GREEN); // back button 469} 470 471//<><><><><><><><><><><><><><><><><><><><><><><><> 472//<><><><><><><><> end screen 0011 <><><><><><><><><> 473//<><><><><><><><><><><><><><><><><><><><><><><><> 474 475//<><><><><><><><><><><><><><><><><><><><><><><><> 476//<><><><><><><><> begin screen 0021 <><><><><><><><> 477//<><><><><><><><><><><><><><><><><><><><><><><><> 478 if(currentScreen == 21){ 479 // " " 480 Tft.drawString("MEGA 2560",00,5,4,BLUE); 481 Tft.drawString("SENSORS",10,50,4,YELLOW); 482 Tft.drawString("PIR Array", 80,130, 3, BLUE); 483 Tft.drawString("Sound", 05, 195, 3, GREEN); 484 Tft.drawString("Head Position", 10, 260, 3, GREEN); 485 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 486 Tft.drawString("<", 0, 160, 3, GREEN); // back button 487} 488//<><><><><><><><><><><><><><><><><><><><><><><><> 489//<><><><><><><><> end screen 0021 <><><><><><><><><> 490//<><><><><><><><><><><><><><><><><><><><><><><><> 491 492//<><><><><><><><><><><><><><><><><><><><><><><><> 493//<><><><><><><><> begin screen 0121 <><><><><><><><> 494//<><><><><><><><><><><><><><><><><><><><><><><><> 495 if(currentScreen == 121){ 496 // " " 497 Tft.drawString("PIR",0,5,4,BLUE); 498 Tft.drawString("ARRAY",10,50,4,YELLOW); 499 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 500 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 501 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 502 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 503 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 504 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 505 Tft.drawString("<", 0, 160, 3, GREEN); // back button 506} 507//<><><><><><><><><><><><><><><><><><><><><><><><> 508//<><><><><><><><> end screen 0121 <><><><><><><><><> 509//<><><><><><><><><><><><><><><><><><><><><><><><> 510 511//<><><><><><><><><><><><><><><><><><><><><><><><> 512//<><><><><><><><> begin screen 0221 <><><><><><><><> 513//<><><><><><><><><><><><><><><><><><><><><><><><> 514 if(currentScreen == 221){ 515 // " " 516 Tft.drawString("SOUND",0,5,4,BLUE); 517 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 518 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 519 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 520 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 521 Tft.drawString("<", 0, 160, 3, GREEN); // back button 522} 523//<><><><><><><><><><><><><><><><><><><><><><><><> 524//<><><><><><><><> end screen 0221 <><><><><><><><><> 525//<><><><><><><><><><><><><><><><><><><><><><><><> 526 527//<><><><><><><><><><><><><><><><><><><><><><><><> 528//<><><><><><><><> begin screen 0031 <><><><><><><><> 529//<><><><><><><><><><><><><><><><><><><><><><><><> 530 if(currentScreen == 31){ 531 // " " 532 Tft.drawString("Bluetooth",0,5,4,BLUE); 533 Tft.drawString("Control",10,50,4,YELLOW); 534 Tft.drawString("On", 80,130, 3, BLUE); 535 Tft.drawString("Off", 05, 195, 3, GREEN); 536 Tft.drawString("Monitor", 10, 260, 3, GREEN); 537 Tft.drawString("<", 0, 160, 3, GREEN); // back button 538} 539//<><><><><><><><><><><><><><><><><><><><><><><><> 540//<><><><><><><><> end screen 0031 <><><><><><><><><> 541//<><><><><><><><><><><><><><><><><><><><><><><><> 542 543//<><><><><><><><><><><><><><><><><><><><><><><><> 544//<><><><><><><><> begin screen 0002 <><><><><><><><> 545//<><><><><><><><><><><><><><><><><><><><><><><><> 546 if(currentScreen == 2){ 547 // " " 548 Tft.drawString("Mouth",0,5,4,BLUE); 549 Tft.drawString("Control",10,50,4,YELLOW); 550 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 551 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 552 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 553 Tft.drawString("<", 0, 160, 3, GREEN); // back button 554} 555//<><><><><><><><><><><><><><><><><><><><><><><><> 556//<><><><><><><><> end screen 0002 <><><><><><><><><> 557//<><><><><><><><><><><><><><><><><><><><><><><><> 558 559 560//<><><><><><><><><><><><><><><><><><><><><><><><> 561//<><><><><><><><> begin screen 0012 <><><><><><><><> 562//<><><><><><><><><><><><><><><><><><><><><><><><> 563 if(currentScreen == 12){ 564 // " " 565 Tft.drawString("Jaw Test",0,5,4,BLUE); 566 Tft.drawString("Operations",10,50,4,YELLOW); 567 Tft.drawString("Open", 80,130, 3, BLUE); 568 Tft.drawString("Close", 05, 195, 3, GREEN); 569 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 570 Tft.drawString("<", 0, 160, 3, GREEN); // back button 571} 572//<><><><><><><><><><><><><><><><><><><><><><><><> 573//<><><><><><><><> end screen 0012 <><><><><><><><><> 574//<><><><><><><><><><><><><><><><><><><><><><><><> 575 576 577//<><><><><><><><><><><><><><><><><><><><><><><><> 578//<><><><><><><><> begin screen 0022 <><><><><><><><> 579//<><><><><><><><><><><><><><><><><><><><><><><><> 580 if(currentScreen == 22){ 581 // " " 582 Tft.drawString("Sound",0,5,4,BLUE); 583 Tft.drawString("Sensors",10,50,4,YELLOW); 584 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 585 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 586 Tft.drawString("Monitor", 10, 260, 3, GREEN); 587 Tft.drawString("<", 0, 160, 3, GREEN); // back button 588} 589//<><><><><><><><><><><><><><><><><><><><><><><><> 590//<><><><><><><><> end screen 0022 <><><><><><><><><> 591//<><><><><><><><><><><><><><><><><><><><><><><><> 592 593 594 595//<><><><><><><><><><><><><><><><><><><><><><><><> 596//<><><><><><><><> begin screen 0122 <><><><><><><><> 597//<><><><><><><><><><><><><><><><><><><><><><><><> 598 if(currentScreen == 122){ 599 // " " 600 Tft.drawString("Alexa Sense",0,5,4,BLUE); 601 Tft.drawString("Operations",10,50,4,YELLOW); 602 Tft.drawString("On", 80,130, 3, BLUE); 603 Tft.drawString("Off", 05, 195, 3, GREEN); 604 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 605 Tft.drawString("<", 0, 160, 3, GREEN); // back button 606} 607//<><><><><><><><><><><><><><><><><><><><><><><><> 608//<><><><><><><><> end screen 0122 <><><><><><><><><> 609//<><><><><><><><><><><><><><><><><><><><><><><><> 610 611//<><><><><><><><><><><><><><><><><><><><><><><><> 612//<><><><><><><><> begin screen 0222 <><><><><><><><> 613//<><><><><><><><><><><><><><><><><><><><><><><><> 614 if(currentScreen == 222){ 615 // " " 616 Tft.drawString("Graves Sense",0,5,4,BLUE); 617 Tft.drawString("Operations",10,50,4,YELLOW); 618 Tft.drawString("On", 80,130, 3, BLUE); 619 Tft.drawString("Off", 05, 195, 3, GREEN); 620 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 621 Tft.drawString("<", 0, 160, 3, GREEN); // back button 622} 623//<><><><><><><><><><><><><><><><><><><><><><><><> 624//<><><><><><><><> end screen 0222 <><><><><><><><><> 625//<><><><><><><><><><><><><><><><><><><><><><><><> 626 627//<><><><><><><><><><><><><><><><><><><><><><><><> 628//<><><><><><><><> begin screen 0032 <><><><><><><><> 629//<><><><><><><><><><><><><><><><><><><><><><><><> 630 if(currentScreen == 32){ 631 // " " 632 Tft.drawString("Sound Sense",0,5,4,BLUE); 633 Tft.drawString("Monitors",10,50,4,YELLOW); 634 Tft.drawString("Alexa", 80,130, 3, BLUE); 635 Tft.drawString("Graves", 05, 195, 3, GREEN); 636 Tft.drawString("<", 0, 160, 3, GREEN); // back button 637} 638//<><><><><><><><><><><><><><><><><><><><><><><><> 639//<><><><><><><><> end screen 0032 <><><><><><><><><> 640//<><><><><><><><><><><><><><><><><><><><><><><><> 641 642//<><><><><><><><><><><><><><><><><><><><><><><><> 643//<><><><><><><><> begin screen 0003 <><><><><><><><> 644//<><><><><><><><><><><><><><><><><><><><><><><><> 645 if(currentScreen == 3){ 646 // " " 647 Tft.drawString("Head Control",0,5,4,BLUE); 648 Tft.drawString("Operations",10,50,4,YELLOW); 649 Tft.drawString("PIR Array", 80,130, 3, BLUE); 650 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 651 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 652 Tft.drawString("<", 0, 160, 3, GREEN); // back button 653} 654//<><><><><><><><><><><><><><><><><><><><><><><><> 655//<><><><><><><><> end screen 0003 <><><><><><><><><> 656//<><><><><><><><><><><><><><><><><><><><><><><><> 657 658//<><><><><><><><><><><><><><><><><><><><><><><><> 659//<><><><><><><><> begin screen 0013 <><><><><><><><> 660//<><><><><><><><><><><><><><><><><><><><><><><><> 661 if(currentScreen == 13){ 662 // " " 663 Tft.drawString("PIR Control",0,5,4,BLUE); 664 Tft.drawString("Operations",10,50,4,YELLOW); 665 Tft.drawString("On", 80,130, 3, BLUE); 666 Tft.drawString("Off", 05, 195, 3, GREEN); 667 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 668 Tft.drawString("<", 0, 160, 3, GREEN); // back button 669} 670//<><><><><><><><><><><><><><><><><><><><><><><><> 671//<><><><><><><><> end screen 0013 <><><><><><><><><> 672//<><><><><><><><><><><><><><><><><><><><><><><><> 673 674//<><><><><><><><><><><><><><><><><><><><><><><><> 675//<><><><><><><><> begin screen 0023 <><><><><><><><> 676//<><><><><><><><><><><><><><><><><><><><><><><><> 677 if(currentScreen == 23){ 678 // " " 679 Tft.drawString("Head Control",0,5,4,BLUE); 680 Tft.drawString("Manual Point",10,50,4,YELLOW); 681 Tft.drawString("Slider", 80,130, 3, BLUE); 682 Tft.drawString("<", 0, 160, 3, GREEN); // back button 683} 684//<><><><><><><><><><><><><><><><><><><><><><><><> 685//<><><><><><><><> end screen 0023 <><><><><><><><><> 686//<><><><><><><><><><><><><><><><><><><><><><><><> 687 688 689////<><><><><><><><><><><><><><><><><><><><><><><><> 690////<><><><><><><><> begin screen lost <><><><><><><><> 691////<><><><><><><><><><><><><><><><><><><><><><><><> 692// else if(currentScreen){ 693// // " " 694// Tft.drawString("Screen not",0,5,3,BLUE); 695// Tft.drawString("found. Please",40,50,3,YELLOW); 696// Tft.drawString("use the back", 80,130, 3, BLUE); 697// Tft.drawString("button to", 05, 195, 3, GREEN); 698// Tft.drawString("return to fun", 10, 260, 3, GREEN); 699// Tft.drawString("<", 0, 160, 3, GREEN); // back button 700//} 701////<><><><><><><><><><><><><><><><><><><><><><><><> 702////<><><><><><><><> end screen lost <><><><><><><><><> 703////<><><><><><><><><><><><><><><><><><><><><><><><> 704 705}// callScreen 706//-------------------------- end callScreen function ------------------------- 707//-------------------------- end callScreen function ------------------------- 708//-------------------------- end callScreen function ------------------------- 709//-------------------------- end callScreen function ------------------------- 710//-------------------------- end callScreen function ------------------------- 711//-------------------------- end callScreen function ------------------------- 712//-------------------------- end callScreen function ------------------------- 713//-------------------------- end callScreen function ------------------------- 714//-------------------------- end callScreen function ------------------------- 715//-------------------------- end callScreen function ------------------------- 716//-------------------------- end callScreen function ------------------------- 717//-------------------------- end callScreen function ------------------------- 718//-------------------------- end callScreen function ------------------------- 719 720 721//**************************************************************************************************** 722//**************************************************************************************************** 723 724 725 726 727 728 729 730//**************************************************************************************************** 731//**************************************************************************************************** 732 733// fin
buttons again
c_cpp
setup new buttons for slider and on off
1/* 2last edit sun oct 14 2018 later in the day 3 4 5gravesmegamaster 6 7graves 8 project 9arduino MEGA 2650 10Master 11coded from scratch by wylie jones 12wyliejones@gmail.com 13 14Graves 15 multi arduino build 10/2018 16Arduino mega 2560 with 240/320 tft and micro sd card 17 (for storing screen backgrounds) 18two arduino uno's 19slave1 arduino uno to sense 20 sound from graves and echo dot to control mouth 21slave2 arduino uno to control 22 passive sensor array and head servo 23 24sound is sensed with a simple DC bias 25 circuit to capture line level input to be used as a digital signal 26 27 analogue 28 pin speaker + 29 \ / 30 (red from speaker) 31 \ / 32 \\ 33 / 34 *--------[=]-----------*---------[=]----------* 35 36 | resistor \ resistor | 37 | \\ 38 | 39 |(red with white) \ |to arduino 40 ground (black with white) 41to arduino 5v+ speaker - 42 (black 43 from speaker) 44 45*/ 46//end notes 47//end notes 48//end notes 49//end notes 50//end 51 notes 52//end notes 53 54 55//********************************************************* 56//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 57//********************************************************* 58 59 60//begin 61 declarations 62//begin declarations 63//begin declarations 64//begin declarations 65//begin 66 declarations 67//begin declarations 68//begin declarations 69 70//#include <TFT.h> 71//#include 72 <Servo.h> 73//#include <stdint.h> 74//#include <SD.h> 75#include <TFTv2.h> 76#include 77 <SPI.h> 78#include <SeeedTouchScreen.h> 79 80//const int PIN_SD_CS = 4; // 81 pin of sd card 82 83TouchScreen ts = TouchScreen(XP, YP, XM, YM); 84int buttonPressed; 85 // stores which button was pressed 86unsigned long newButtonTime; // debounce 87unsigned 88 long oldButtonTime; // debounce 89unsigned long buttonTimeDifference; // debounce 90unsigned 91 long debounceTime; // debounce 92int currentScreen; // identifies current screen 93 by adding x y and z 94int x; // for ones 95int y; // for tens 96int z; // for 97 hundreds 98 99int zMax; // maximum pressure to detect 100int zMin; // minimum 101 pressure to detect 102unsigned long backlightTimer; // for backlight timeout 103int 104 backLightState; // status of backlight 1 for on and 0 for off 105unsigned long 106 backlightTimeDifference; 107unsigned long newBacklightTime; 108unsigned long oldBacklightTime; 109 110int 111 incomingMouthByte; 112int outgoingMouthByte; 113int mouthOnOff; 114int incomingHeadByte; 115int 116 outgoingHeadByte; 117int headOnOff; 118 119//end declarations 120//end declarations 121//end 122 declarations 123//end declarations 124//end declarations 125//end declarations 126//end 127 declarations 128//end declarations 129//end declarations 130 131//********************************************************* 132//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 133//********************************************************* 134 135// 136 begin void setup 137// begin void setup 138// begin void setup 139// begin void 140 setup 141// begin void setup 142// begin void setup 143// begin void setup 144// 145 begin void setup 146// begin void setup 147// begin void setup 148// begin void 149 setup 150void setup() { 151Serial.begin(9600); 152 oldButtonTime = millis(); 153 154 newButtonTime = millis(); 155 Tft.TFTinit(); // init TFT library 156 TFT_BL_ON; 157 // turn on the background light 158 backLightState = 1; 159 x = 0; 160 y 161 = 0; 162 z = 0; 163 buttonPressed = 4; 164incomingHeadByte = 0; 165incomingMouthByte 166 = 0; 167 168 //////////////////////////////// 169 //// 170 manually set variables //// 171 //////////////////////////////// 172 173 174 debounceTime = 1000; // button debounce in milliseconds 175 zMax 176 = 460; // maximum pressure to detect 177 zMin = 100; // minimum pressure 178 to detect 179 backlightTimer = 5000; // for backlight timeout 180 181 182 183 currentScreen = 0; 184 callScreen(); 185 186} //void setup() 187// end void 188 setup 189// end void setup 190// end void setup 191// end void setup 192// end void 193 setup 194// end void setup 195// end void setup 196// end void setup 197 198//********************************************************* 199//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 200//********************************************************* 201 202// 203 begin void loop 204// begin void loop 205// begin void loop 206// begin void loop 207// 208 begin void loop 209// begin void loop 210// begin void loop 211// begin void loop 212// 213 begin void loop 214// begin void loop 215// begin void loop 216// begin void loop 217// 218 begin void loop 219// begin void loop 220 221void loop() { 222 tftBacklightTimeout( 223 ); // check time and turn off backlight 224 tftButtonGroup0(); // gather information 225 from touch screen touches 226 buttonTimeDifference = newButtonTime - oldButtonTime; 227 228 if(debounceTime < buttonTimeDifference){ 229 whatScreen(); 230 callScreen(); 231 232 oldButtonTime = newButtonTime; 233 showStuff(); // serial prints 234 tftDisplay(); 235 // display x y coordinates on tft display 236 } 237// serialDoStuff(); 238} //void 239 loop() 240 241// end of void loop 242// end of void loop 243// end of void loop 244// 245 end of void loop 246// end of void loop 247// end of void loop 248// end of void 249 loop 250// end of void loop 251// end of void loop 252// end of void loop 253// 254 end of void loop 255// end of void loop 256// end of void loop 257// end of void 258 loop 259// end of void loop 260 261//**************************************************************************************************** 262//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 263//**************************************************************************************************** 264///////////////////////////////////////////////////////////////////////////////////////////////////////// 265///////////////////////////////////////// 266 functions /////////////////////////////////////////////////// 267///////////////////////////////////////////////////////////////////////////////////////////////////////// 268//**************************************************************************************************** 269//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 270//**************************************************************************************************** 271 272//--------------------------begin 273 tftBacklightTimeout---------------------------------- 274void tftBacklightTimeout(){ 275 276 newBacklightTime = millis(); 277 if(backLightState = 0){ 278 backlightTimeDifference 279 = newBacklightTime - oldBacklightTime; 280 if(backlightTimer > backlightTimeDifference){ 281 282 backlightTimeDifference = newBacklightTime - oldBacklightTime; 283 TFT_BL_ON; 284 // turn on the background light 285 backLightState = 1; 286 oldBacklightTime 287 = millis(); 288 } 289 } 290 if(backLightState = 1){ 291 backlightTimeDifference 292 = newBacklightTime - oldBacklightTime; 293 if(backlightTimer < backlightTimeDifference){ 294 295 backlightTimeDifference = newBacklightTime - oldBacklightTime; 296 TFT_BL_OFF; 297 // turn off the background light 298 backLightState = 0; 299 oldBacklightTime 300 = millis(); 301 } 302 } 303} 304//--------------------------end tftBacklightTimeout---------------------------------- 305 306//**************************************************************************************************** 307//**************************************************************************************************** 308 309//--------------------------begin 310 tftButtonGroup0---------------------------------- 311//--------------------------begin 312 tftButtonGroup0---------------------------------- 313//--------------------------begin 314 tftButtonGroup0---------------------------------- 315//--------------------------begin 316 tftButtonGroup0---------------------------------- 317int tftButtonGroup0(){ 318 319 Point p = ts.getPoint(); 320 if(zMin<p.z && p.z<zMax){ 321 TFT_BL_ON; // 322 turn on the background light 323 backLightState = 1; 324 oldBacklightTime 325 = millis(); 326 newButtonTime = millis(); 327 p.x = map(p.x, TS_MINX, TS_MAXX, 328 0, 240); 329 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 330//Button 1 331 if(75<p.x 332 && p.x<140){ 333 if(100<p.y && p.y<164){ 334 buttonPressed = 1; 335 336 } 337//Button 2 338 if(164<p.y && p.y<240){ 339 buttonPressed 340 = 2; 341 } 342//Button 3 343 if(240<p.y && p.y<310){ 344 buttonPressed 345 = 3; 346 } 347 } 348 } 349//Button 4 350 if(10<p.x && p.x<75){ 351 352 if(100<p.y && p.y<240){ 353 buttonPressed = 4; 354 } 355 356 } 357//Button 5 358 if(250<p.x && p.x<275){ 359 if(0<p.y 360 && p.y<75){ 361 buttonPressed = 5; 362 } 363 } 364}//void tftButtonGroup0 365//--------------------------end 366 tftButtonGroup0 code---------------------------------- 367//--------------------------end 368 tftButtonGroup0 code---------------------------------- 369//--------------------------end 370 tftButtonGroup0 code---------------------------------- 371//--------------------------end 372 tftButtonGroup0 code---------------------------------- 373//--------------------------end 374 tftButtonGroup0 code---------------------------------- 375//**************************************************************************************************** 376//**************************************************************************************************** 377 378//--------------------------begin 379 tftButtonGroup1---------------------------------- 380//--------------------------begin 381 tftButtonGroup1---------------------------------- 382//--------------------------begin 383 tftButtonGroup1---------------------------------- 384//--------------------------begin 385 tftButtonGroup1---------------------------------- 386int tftButtonGroup1(){ // 387 for mouth 388 Point p = ts.getPoint(); 389 if(zMin<p.z && p.z<zMax){ 390 TFT_BL_ON; 391 // turn on the background light 392 backLightState = 1; 393 oldBacklightTime 394 = millis(); 395 newButtonTime = millis(); 396 p.x = map(p.x, TS_MINX, TS_MAXX, 397 0, 240); 398 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 399//Button 1 400 if(75<p.x 401 && p.x<140){ 402 if(100<p.y && p.y<164){ 403 mouthOnOff = 1; // on 404 405 } 406//Button 2 407 if(164<p.y && p.y<240){ 408 mouthOnOff 409 = 0; // off 410 } 411//Button 3 412// if(240<p.y && p.y<310){ 413// 414 buttonPressed = 3; 415// } 416// } 417 } 418//Button 4 419 420 if(10<p.x && p.x<75){ 421 if(100<p.y && p.y<240){ 422 buttonPressed 423 = 4; 424 } 425 } 426}//void tftButtonGroup1 427//--------------------------end 428 tftButtonGroup1 code---------------------------------- 429//--------------------------end 430 tftButtonGroup1 code---------------------------------- 431//--------------------------end 432 tftButtonGroup1 code---------------------------------- 433//--------------------------end 434 tftButtonGroup1 code---------------------------------- 435//--------------------------end 436 tftButtonGroup1 code---------------------------------- 437//**************************************************************************************************** 438//**************************************************************************************************** 439 440//--------------------------begin 441 tftButtonGroup2---------------------------------- 442//--------------------------begin 443 tftButtonGroup2---------------------------------- 444//--------------------------begin 445 tftButtonGroup2---------------------------------- 446//--------------------------begin 447 tftButtonGroup2---------------------------------- 448int tftButtonGroup2(){ // 449 for head 450 Point p = ts.getPoint(); 451 if(zMin<p.z && p.z<zMax){ 452 TFT_BL_ON; 453 // turn on the background light 454 backLightState = 1; 455 oldBacklightTime 456 = millis(); 457 newButtonTime = millis(); 458 p.x = map(p.x, TS_MINX, TS_MAXX, 459 0, 240); 460 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 461//Button 1 462 if(75<p.x 463 && p.x<140){ 464 if(100<p.y && p.y<164){ 465 headOnOff = 1; // on 466 467 } 468//Button 2 469 if(164<p.y && p.y<240){ 470 headOnOff 471 = 0; // off 472 } 473//Button 3 474// if(240<p.y && p.y<310){ 475// 476 buttonPressed = 3; 477// } 478// } 479 } 480//Button 4 481 482 if(10<p.x && p.x<75){ 483 if(100<p.y && p.y<240){ 484 buttonPressed 485 = 4; 486 } 487 } 488}//void tftButtonGroup2 489//--------------------------end 490 tftButtonGroup2 code---------------------------------- 491//--------------------------end 492 tftButtonGroup2 code---------------------------------- 493//--------------------------end 494 tftButtonGroup2 code---------------------------------- 495//--------------------------end 496 tftButtonGroup2 code---------------------------------- 497//--------------------------end 498 tftButtonGroup2 code---------------------------------- 499//**************************************************************************************************** 500//**************************************************************************************************** 501//-------------------------- 502 begin whatScreen function ------------------------- 503//-------------------------- 504 begin whatScreen function ------------------------- 505//-------------------------- 506 begin whatScreen function ------------------------- 507//-------------------------- 508 begin whatScreen function ------------------------- 509 510int whatScreen(){ 511 512 if(x == 0){ 513 if(buttonPressed == 1){ 514 x = x + 1; 515 Serial.println("x 516 + 1"); 517 } 518 if(buttonPressed == 2){ 519 x = x + 2; 520 Serial.println("x 521 + 2"); 522 } 523 if(buttonPressed == 3){ 524 x = x + 3; 525 Serial.println("x 526 + 3"); 527 } 528 if(buttonPressed == 4){ 529 x = 0; 530 Serial.println("x 531 = 0"); 532 } 533 if(buttonPressed == 5){ 534 x = 0; 535 y 536 = 0; 537 z = 0; 538 Serial.println("xyz all 0"); 539 } 540 541 } 542 else if(x >> 0){ 543 if(y == 0){ 544 if(buttonPressed == 545 1){ 546 y = y + 10; 547 Serial.println("y + 10"); 548 } 549 550 if(buttonPressed == 2){ 551 y = y + 20; 552 Serial.println("y 553 + 20"); 554 } 555 if(buttonPressed == 3){ 556 y = y + 30; 557 558 Serial.println("y + 30"); 559 } 560 if(buttonPressed == 561 4){ 562 x = 0; 563 Serial.println("x = 0"); 564 } 565 566 if(buttonPressed == 5){ 567 x = 0; 568 y = 0; 569 z 570 = 0; 571 Serial.println("xyz all 0"); 572 } 573 } 574 else 575 if (y >> 0){ 576 if(buttonPressed == 1){ 577 z = z + 100; 578 579 Serial.println("z + 100"); 580 } 581 if(buttonPressed 582 == 2){ 583 z = z + 200; 584 Serial.println("z + 200"); 585 586 } 587 if(buttonPressed == 3){ 588 z = z + 300; 589 590 Serial.println("z + 300"); 591 } 592 if(buttonPressed 593 == 4){ 594 if(z == 0){ 595 y = 0; 596 Serial.println("y 597 = 0"); 598 } 599 else if(z >> 0){ 600 z = 0; 601 602 Serial.println("z = 0"); 603 } 604 } 605 if(buttonPressed 606 == 5){ 607 x = 0; 608 y = 0; 609 z = 0; 610 Serial.println("xyz 611 all 0"); 612 } 613 }//y>0 614 }//x>0 615 currentScreen = 616 z+y+x; 617} 618//-------------------------- end whatScreen function ------------------------- 619//-------------------------- 620 end whatScreen function ------------------------- 621//-------------------------- 622 end whatScreen function ------------------------- 623//-------------------------- 624 end whatScreen function ------------------------- 625//-------------------------- 626 end whatScreen function ------------------------- 627 628//**************************************************************************************************** 629//**************************************************************************************************** 630 631//--------------------------begin 632 mouthUnoTxRx---------------------------------- 633 634void mouthUnoTxRx(){ 635 636 637 //mouthOnOff code? 638 Serial1.write(1); // send a byte with the value 45 639 if 640 (Serial1.available() > 0) { 641 // read the incoming byte: 642 incomingMouthByte 643 = Serial1.read(); 644 } 645} 646 647//--------------------------end mouthUnoTxRx 648 -------------------------------------- 649//--------------------------begin headUnoTxRx 650 -------------------------------------- 651 652// call slave1 arduino for data 653 654 //headOnOff code? 655void headUnoTxRx(){ 656 Serial2.write(1); // send a byte 657 with the value 45 658 if (Serial2.available() > 0) { 659 // read the incoming 660 byte: 661 incomingHeadByte = Serial2.read(); 662 } 663 664} 665 666// 667 call slave2 arduino for data 668//--------------------------end headUnoTxRx -------------------------------------- 669 670//**************************************************************************************************** 671//**************************************************************************************************** 672 673//--------------------------begin 674 tftDisplay code---------------------------------- 675void tftDisplay(){ 676 Point 677 p = ts.getPoint(); 678 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 679 p.y = map(p.y, 680 TS_MINY, TS_MAXY, 0, 320); 681 Tft.fillRectangle(0, 160, 60, 30, BLACK); 682 683 Tft.drawNumber((p.x), 0, 160, 3, GREEN); 684 Tft.fillRectangle(180, 160, 685 60, 30, BLACK); 686 Tft.drawNumber((p.y), 180, 160, 3, GREEN); 687 Tft.fillRectangle(80, 688 160, 60, 30, BLACK); 689 Tft.drawNumber((buttonPressed), 80, 160, 3, GREEN); 690}// 691 void tftDisplay 692//--------------------------end tftDisplay code------------------------------------ 693 694//**************************************************************************************************** 695//**************************************************************************************************** 696 697//-------------------------- 698 begin mouth on off function -------------------------- 699//-------------------------- 700 end mouth on off function -------------------------- 701 702//**************************************************************************************************** 703//**************************************************************************************************** 704 705//-------------------------- 706 begin head on off function -------------------------- 707//-------------------------- 708 end head on off function ------------------------- 709 710//**************************************************************************************************** 711//**************************************************************************************************** 712 713//-------------------------- 714 begin serial display function -------------------------- 715void showStuff(){ 716 717 Serial.println("------/ last update /-------"); 718// Serial.println("------begin 719 display-------"); 720 Serial.print("buttonPressed "); 721 Serial.println(buttonPressed); 722 723 Serial.print("x "); 724 Serial.println(x); 725 Serial.print("y "); 726 727 Serial.println(y); 728 Serial.print("z "); 729 Serial.println(z); 730 Serial.print("currentScreen 731 "); 732 Serial.println(currentScreen); 733// Serial.println("-------end display--------"); 734 735 Serial.println(""); 736 Serial.println(""); 737 Serial.println(""); 738 739 } 740//-------------------------- end serial display function ------------------------- 741 742 743//**************************************************************************************************** 744//**************************************************************************************************** 745 746//--------------------------- 747 Primary screen maps -------------------------------- 748/* 749******** 750updates 751 needed 752******** 7531 ditch the contrast 7542 ditch the brightness 7553 setup 756 screen timeout 757 758 759 760 761screen 0000 A)Home 762 screen 0001 a)settings 763 764 screen 0011 -brightness 765 screen 0011 -contrast 766 screen 0011 -screen 767 lock time out 768 screen 0001 b)sensor monitors 769 screen 0021 -pir 770 screen 771 0121 *report pir detection 772 screen 0021 -sound 773 screen 0221 *sense 774 alexa sound 775 screen 0221 *sense graves sound 776 screen 0221 *report 777 mouth servo position 778 screen 0221 *adjust sensitivity? 779 screen 0021 780 -head potentiometer 781 screen 0021 -bluetooth 782 screen 0001 c)bluetooth 783 784 screen 0031 -on 785 screen 0031 -off 786 screen 0031 -monitor 787screen 788 0000 B)Mouth Control 789 screen 0002 a)test button 790 screen 0012 -open 791 792 screen 0012 -close 793 screen 0012 -push button chicken switch 794 screen 795 0002 b)sound sensors on/off 796 screen 0022 -alexa sense 797 screen 798 0122 *on 799 screen 0122 *off 800 screen 0122 *monitor sensor 801 screen 802 0022 -graves sense 803 screen 0222 *on 804 screen 0222 *off 805 806 screen 0222 *monitor sensors 807 screen 0002 c)sound sensor status 808 809 screen 0032 -alexa 810 screen 0032 -graves 811screen 0000 C)Head Control 812 813 screen 0003 a)pir on/off 814 screen 0013 -on 815 screen 0013 -off 816 817 screen 0013 -sensor 818 screen 0003 b)manual point 819 screen 0023 -slider 820*/ 821//**************************************************************************************************** 822//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 823//**************************************************************************************************** 824//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 825//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 826 screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 827//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 828//**************************************************************************************************** 829//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 830//**************************************************************************************************** 831 832//-------------------------- 833 begin callScreen function ------------------------- 834//-------------------------- 835 begin callScreen function ------------------------- 836//-------------------------- 837 begin callScreen function ------------------------- 838//-------------------------- 839 begin callScreen function ------------------------- 840//-------------------------- 841 begin callScreen function ------------------------- 842//-------------------------- 843 begin callScreen function ------------------------- 844//-------------------------- 845 begin callScreen function ------------------------- 846//-------------------------- 847 begin callScreen function ------------------------- 848//-------------------------- 849 begin callScreen function ------------------------- 850//-------------------------- 851 begin callScreen function ------------------------- 852//-------------------------- 853 begin callScreen function ------------------------- 854 855int callScreen(){ 856 857 Tft.fillRectangle(0, 0, 240, 320, BLACK); 858 859//<><><><><><><><><><><><><><><><><><><><><><><><> 860//<><><><><><><><> 861 begin screen 0000 master <><><><><><><><> 862//<><><><><><><><><><><><><><><><><><><><><><><><> 863if(currentScreen 864 == 0){ 865 // " " 866 Tft.drawString("GRAVES",0,5,4, 867 GREEN); 868 Tft.drawString("INTERFACE",10,50,4,GREEN); 869 Tft.drawString("Home", 870 80,130, 3, GREEN); 871 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 872 873 Tft.drawString("Head Control", 10, 260, 3, GREEN); 874} 875//<><><><><><><><><><><><><><><><><><><><><><><><> 876//<><><><><><><><> 877 end screen 0000 master <><><><><><><><><> 878//<><><><><><><><><><><><><><><><><><><><><><><><> 879 880//<><><><><><><><><><><><><><><><><><><><><><><><> 881//<><><><><><><><> 882 begin screen 0001 <><><><><><><><> 883//<><><><><><><><><><><><><><><><><><><><><><><><> 884 885 if(currentScreen == 1){ 886 // " " 887 Tft.drawString("MEGA 888 2560",00,5,4,BLUE); 889 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 890 Tft.drawString("Settings", 891 10,130, 3, BLUE); 892 Tft.drawString("Sensors", 20, 195, 3, BLUE); 893 Tft.drawString("Bluetooth", 894 00, 260, 3, BLUE); 895 Tft.drawString("<", 0, 160, 3, GREEN); // back button 896} 897//<><><><><><><><><><><><><><><><><><><><><><><><> 898//<><><><><><><><> 899 end screen 0001 <><><><><><><><><> 900//<><><><><><><><><><><><><><><><><><><><><><><><> 901 902//<><><><><><><><><><><><><><><><><><><><><><><><> 903//<><><><><><><><> 904 begin screen 0011 <><><><><><><><> 905//<><><><><><><><><><><><><><><><><><><><><><><><> 906 907 if(currentScreen == 11){ 908 // " " 909 Tft.drawString("MEGA 910 2560",00,5,4,BLUE); 911 Tft.drawString("SETTINGS",10,50,4,YELLOW); 912 Tft.drawString("Brightness", 913 80,130, 3, BLUE); 914 Tft.drawString("Contrast", 05, 195, 3, GREEN); 915 916 Tft.drawString("Timeout", 10, 260, 3, GREEN); 917 Tft.drawString("<", 918 0, 160, 3, GREEN); // back button 919} 920 921//<><><><><><><><><><><><><><><><><><><><><><><><> 922//<><><><><><><><> 923 end screen 0011 <><><><><><><><><> 924//<><><><><><><><><><><><><><><><><><><><><><><><> 925 926//<><><><><><><><><><><><><><><><><><><><><><><><> 927//<><><><><><><><> 928 begin screen 0021 <><><><><><><><> 929//<><><><><><><><><><><><><><><><><><><><><><><><> 930 931 if(currentScreen == 21){ 932 // " " 933 Tft.drawString("MEGA 934 2560",00,5,4,BLUE); 935 Tft.drawString("SENSORS",10,50,4,YELLOW); 936 Tft.drawString("PIR 937 Array", 80,130, 3, BLUE); 938 Tft.drawString("Sound", 05, 195, 3, GREEN); 939 940 Tft.drawString("Head Position", 10, 260, 3, GREEN); 941 Tft.drawString("Bluetooth", 942 10, 260, 3, GREEN); 943 Tft.drawString("<", 0, 160, 3, GREEN); // back button 944} 945//<><><><><><><><><><><><><><><><><><><><><><><><> 946//<><><><><><><><> 947 end screen 0021 <><><><><><><><><> 948//<><><><><><><><><><><><><><><><><><><><><><><><> 949 950//<><><><><><><><><><><><><><><><><><><><><><><><> 951//<><><><><><><><> 952 begin screen 0121 <><><><><><><><> 953//<><><><><><><><><><><><><><><><><><><><><><><><> 954 955 if(currentScreen == 121){ 956 // " " 957 Tft.drawString("PIR",0,5,4,BLUE); 958 959 Tft.drawString("ARRAY",10,50,4,YELLOW); 960 Tft.drawString("PIR sensor 961 #", 80, 60, 3, BLUE); 962 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 963 964 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 965 Tft.drawString("PIR 966 sensor #", 80, 130, 3, BLUE); 967 Tft.drawString("PIR sensor #", 80, 130, 968 3, BLUE); 969 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 970 Tft.drawString("<", 971 0, 160, 3, GREEN); // back button 972} 973//<><><><><><><><><><><><><><><><><><><><><><><><> 974//<><><><><><><><> 975 end screen 0121 <><><><><><><><><> 976//<><><><><><><><><><><><><><><><><><><><><><><><> 977 978//<><><><><><><><><><><><><><><><><><><><><><><><> 979//<><><><><><><><> 980 begin screen 0221 <><><><><><><><> 981//<><><><><><><><><><><><><><><><><><><><><><><><> 982 983 if(currentScreen == 221){ 984 // " " 985 Tft.drawString("SOUND",0,5,4,BLUE); 986 987 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 988 Tft.drawString("Sense 989 Graves", 80,130, 3, BLUE); 990 Tft.drawString("Jaw position", 05, 195, 3, 991 GREEN); 992 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 993 Tft.drawString("<", 994 0, 160, 3, GREEN); // back button 995} 996//<><><><><><><><><><><><><><><><><><><><><><><><> 997//<><><><><><><><> 998 end screen 0221 <><><><><><><><><> 999//<><><><><><><><><><><><><><><><><><><><><><><><> 1000 1001//<><><><><><><><><><><><><><><><><><><><><><><><> 1002//<><><><><><><><> 1003 begin screen 0031 <><><><><><><><> 1004//<><><><><><><><><><><><><><><><><><><><><><><><> 1005 1006 if(currentScreen == 31){ 1007 // " " 1008 Tft.drawString("Bluetooth",0,5,4,BLUE); 1009 1010 Tft.drawString("Control",10,50,4,YELLOW); 1011 Tft.drawString("On", 1012 80,130, 3, BLUE); 1013 Tft.drawString("Off", 05, 195, 3, GREEN); 1014 Tft.drawString("Monitor", 1015 10, 260, 3, GREEN); 1016 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1017} 1018//<><><><><><><><><><><><><><><><><><><><><><><><> 1019//<><><><><><><><> 1020 end screen 0031 <><><><><><><><><> 1021//<><><><><><><><><><><><><><><><><><><><><><><><> 1022 1023//<><><><><><><><><><><><><><><><><><><><><><><><> 1024//<><><><><><><><> 1025 begin screen 0002 <><><><><><><><> 1026//<><><><><><><><><><><><><><><><><><><><><><><><> 1027 1028 if(currentScreen == 2){ 1029 // " " 1030 Tft.drawString("Mouth",0,5,4,BLUE); 1031 1032 Tft.drawString("Control",10,50,4,YELLOW); 1033 Tft.drawString("Test 1034 Jaw", 80,130, 3, BLUE); 1035 Tft.drawString("Sensor on/off", 05, 195, 3, 1036 GREEN); 1037 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1038 Tft.drawString("<", 1039 0, 160, 3, GREEN); // back button 1040 } 1041//<><><><><><><><><><><><><><><><><><><><><><><><> 1042//<><><><><><><><> 1043 end screen 0002 <><><><><><><><><> 1044//<><><><><><><><><><><><><><><><><><><><><><><><> 1045 1046 1047//<><><><><><><><><><><><><><><><><><><><><><><><> 1048//<><><><><><><><> 1049 begin screen 0012 <><><><><><><><> 1050//<><><><><><><><><><><><><><><><><><><><><><><><> 1051 1052 if(currentScreen == 12){ 1053 // " " 1054 Tft.drawString("Jaw 1055 Test",0,5,4,BLUE); 1056 Tft.drawString("Operations",10,50,4,YELLOW); 1057 1058 Tft.drawString("Open", 80,130, 3, BLUE); 1059 Tft.drawString("Close", 1060 05, 195, 3, GREEN); 1061 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 1062 1063 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1064} 1065//<><><><><><><><><><><><><><><><><><><><><><><><> 1066//<><><><><><><><> 1067 end screen 0012 <><><><><><><><><> 1068//<><><><><><><><><><><><><><><><><><><><><><><><> 1069 1070 1071//<><><><><><><><><><><><><><><><><><><><><><><><> 1072//<><><><><><><><> 1073 begin screen 0022 <><><><><><><><> 1074//<><><><><><><><><><><><><><><><><><><><><><><><> 1075 1076 if(currentScreen == 22){ 1077 // " " 1078 Tft.drawString("Sound",0,5,4,BLUE); 1079 1080 Tft.drawString("Sensors",10,50,4,YELLOW); 1081 Tft.drawString("Alexa 1082 Sense", 80,130, 3, BLUE); 1083 Tft.drawString("Graves Sense", 05, 195, 3, 1084 GREEN); 1085 Tft.drawString("Monitor", 10, 260, 3, GREEN); 1086 Tft.drawString("<", 1087 0, 160, 3, GREEN); // back button 1088} 1089//<><><><><><><><><><><><><><><><><><><><><><><><> 1090//<><><><><><><><> 1091 end screen 0022 <><><><><><><><><> 1092//<><><><><><><><><><><><><><><><><><><><><><><><> 1093 1094 1095 1096//<><><><><><><><><><><><><><><><><><><><><><><><> 1097//<><><><><><><><> 1098 begin screen 0122 <><><><><><><><> 1099//<><><><><><><><><><><><><><><><><><><><><><><><> 1100 1101 if(currentScreen == 122){ 1102 // " " 1103 Tft.drawString("Alexa 1104 Sense",0,5,4,BLUE); 1105 Tft.drawString("Operations",10,50,4,YELLOW); 1106 1107 Tft.drawString("On", 80,130, 3, BLUE); 1108 Tft.drawString("Off", 1109 05, 195, 3, GREEN); 1110 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1111 1112 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1113} 1114//<><><><><><><><><><><><><><><><><><><><><><><><> 1115//<><><><><><><><> 1116 end screen 0122 <><><><><><><><><> 1117//<><><><><><><><><><><><><><><><><><><><><><><><> 1118 1119//<><><><><><><><><><><><><><><><><><><><><><><><> 1120//<><><><><><><><> 1121 begin screen 0222 <><><><><><><><> 1122//<><><><><><><><><><><><><><><><><><><><><><><><> 1123 1124 if(currentScreen == 222){ 1125 // " " 1126 Tft.drawString("Graves 1127 Sense",0,5,4,BLUE); 1128 Tft.drawString("Operations",10,50,4,YELLOW); 1129 1130 Tft.drawString("On", 80,130, 3, BLUE); 1131 Tft.drawString("Off", 1132 05, 195, 3, GREEN); 1133 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1134 1135 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1136} 1137//<><><><><><><><><><><><><><><><><><><><><><><><> 1138//<><><><><><><><> 1139 end screen 0222 <><><><><><><><><> 1140//<><><><><><><><><><><><><><><><><><><><><><><><> 1141 1142//<><><><><><><><><><><><><><><><><><><><><><><><> 1143//<><><><><><><><> 1144 begin screen 0032 <><><><><><><><> 1145//<><><><><><><><><><><><><><><><><><><><><><><><> 1146 1147 if(currentScreen == 32){ 1148 // " " 1149 Tft.drawString("Sound 1150 Sense",0,5,4,BLUE); 1151 Tft.drawString("Monitors",10,50,4,YELLOW); 1152 Tft.drawString("Alexa", 1153 80,130, 3, BLUE); 1154 Tft.drawString("Graves", 05, 195, 3, GREEN); 1155 Tft.drawString("<", 1156 0, 160, 3, GREEN); // back button 1157} 1158//<><><><><><><><><><><><><><><><><><><><><><><><> 1159//<><><><><><><><> 1160 end screen 0032 <><><><><><><><><> 1161//<><><><><><><><><><><><><><><><><><><><><><><><> 1162 1163//<><><><><><><><><><><><><><><><><><><><><><><><> 1164//<><><><><><><><> 1165 begin screen 0003 <><><><><><><><> 1166//<><><><><><><><><><><><><><><><><><><><><><><><> 1167 1168 if(currentScreen == 3){ 1169 // " " 1170 Tft.drawString("Head 1171 Control",0,5,4,BLUE); 1172 Tft.drawString("Operations",10,50,4,YELLOW); 1173 1174 Tft.drawString("PIR Array", 80,130, 3, BLUE); 1175 Tft.drawString("Motor 1176 On/Off", 05, 195, 3, GREEN); 1177 Tft.drawString("Manual Point", 10, 260, 1178 3, GREEN); 1179 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1180} 1181//<><><><><><><><><><><><><><><><><><><><><><><><> 1182//<><><><><><><><> 1183 end screen 0003 <><><><><><><><><> 1184//<><><><><><><><><><><><><><><><><><><><><><><><> 1185 1186//<><><><><><><><><><><><><><><><><><><><><><><><> 1187//<><><><><><><><> 1188 begin screen 0013 <><><><><><><><> 1189//<><><><><><><><><><><><><><><><><><><><><><><><> 1190 1191 if(currentScreen == 13){ 1192 // " " 1193 Tft.drawString("PIR 1194 Control",0,5,4,BLUE); 1195 Tft.drawString("Operations",10,50,4,YELLOW); 1196 1197 Tft.drawString("On", 80,130, 3, BLUE); 1198 Tft.drawString("Off", 1199 05, 195, 3, GREEN); 1200 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 1201 1202 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1203} 1204//<><><><><><><><><><><><><><><><><><><><><><><><> 1205//<><><><><><><><> 1206 end screen 0013 <><><><><><><><><> 1207//<><><><><><><><><><><><><><><><><><><><><><><><> 1208 1209//<><><><><><><><><><><><><><><><><><><><><><><><> 1210//<><><><><><><><> 1211 begin screen 0023 <><><><><><><><> 1212//<><><><><><><><><><><><><><><><><><><><><><><><> 1213 1214 if(currentScreen == 23){ 1215 // " " 1216 Tft.drawString("Head 1217 Control",0,5,4,BLUE); 1218 Tft.drawString("Manual Point",10,50,4,YELLOW); 1219 1220 Tft.drawString("Slider", 80,130, 3, BLUE); 1221 Tft.drawString("<", 1222 0, 160, 3, GREEN); // back button 1223} 1224//<><><><><><><><><><><><><><><><><><><><><><><><> 1225//<><><><><><><><> 1226 end screen 0023 <><><><><><><><><> 1227//<><><><><><><><><><><><><><><><><><><><><><><><> 1228 1229 1230////<><><><><><><><><><><><><><><><><><><><><><><><> 1231////<><><><><><><><> 1232 begin screen lost <><><><><><><><> 1233////<><><><><><><><><><><><><><><><><><><><><><><><> 1234// 1235 else if(currentScreen){ 1236// // " " 1237// 1238 Tft.drawString("Screen not",0,5,3,BLUE); 1239// Tft.drawString("found. 1240 Please",40,50,3,YELLOW); 1241// Tft.drawString("use the back", 80,130, 3, 1242 BLUE); 1243// Tft.drawString("button to", 05, 195, 3, GREEN); 1244// Tft.drawString("return 1245 to fun", 10, 260, 3, GREEN); 1246// Tft.drawString("<", 0, 160, 3, GREEN); 1247 // back button 1248//} 1249////<><><><><><><><><><><><><><><><><><><><><><><><> 1250////<><><><><><><><> 1251 end screen lost <><><><><><><><><> 1252////<><><><><><><><><><><><><><><><><><><><><><><><> 1253 1254}// 1255 callScreen 1256//-------------------------- end callScreen function ------------------------- 1257//-------------------------- 1258 end callScreen function ------------------------- 1259//-------------------------- 1260 end callScreen function ------------------------- 1261//-------------------------- 1262 end callScreen function ------------------------- 1263//-------------------------- 1264 end callScreen function ------------------------- 1265//-------------------------- 1266 end callScreen function ------------------------- 1267//-------------------------- 1268 end callScreen function ------------------------- 1269//-------------------------- 1270 end callScreen function ------------------------- 1271//-------------------------- 1272 end callScreen function ------------------------- 1273//-------------------------- 1274 end callScreen function ------------------------- 1275//-------------------------- 1276 end callScreen function ------------------------- 1277//-------------------------- 1278 end callScreen function ------------------------- 1279//-------------------------- 1280 end callScreen function ------------------------- 1281 1282 1283//**************************************************************************************************** 1284//**************************************************************************************************** 1285 1286 1287 1288 1289 1290 1291 1292//**************************************************************************************************** 1293//**************************************************************************************************** 1294 1295// 1296 fin
24102018 Mega code
c_cpp
Screens partially updated. New button groups need adjustment to couple correct screen assignments.
1/* 224102018 3 4gravesmegamaster 5 6graves project 7arduino MEGA 2650 8Master 9coded from scratch by wylie jones 10wyliejones@gmail.com 11 12Graves multi arduino build 10/2018 13Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 14two arduino uno's 15slave1 arduino uno to sense sound from graves and echo dot to control mouth 16slave2 arduino uno to control passive sensor array and head servo 17 18sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 19 20 analogue pin speaker + 21 \(yellow signal / (red from speaker) 22 10k Ohm \ wire) / 23 resistor \ / 24 *--------/\\/\\/---------*---------/\\/\\/--------* 25 | \ 10k Ohm | 26 | \ resistor | 27 |(red with white) \ |to arduino ground (black with white) 28to arduino 5v+ -)|- 29 \ 100uF 16v 30 \ capacitor 31 \\ 32 \\ 33 speaker - 34 (black from speaker) 35 36*/ 37//end notes 38//end notes 39//end notes 40//end notes 41//end notes 42//end notes 43 44 45//********************************************************* 46//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 47//********************************************************* 48 49 50//begin declarations 51//begin declarations 52//begin declarations 53//begin declarations 54//begin declarations 55//begin declarations 56//begin declarations 57 58//#include <TFT.h> 59//#include <Servo.h> 60//#include <stdint.h> 61//#include <SD.h> 62#include <TFTv2.h> 63#include <SPI.h> 64#include <SeeedTouchScreen.h> 65//#include <Wire.h> 66 67//const int PIN_SD_CS = 4; // pin of sd card 68 69TouchScreen ts = TouchScreen(XP, YP, XM, YM); 70int zMax; // maximum pressure to detect 71int zMin; // minimum pressure to detect 72 73int buttonPressed; // stores which button was pressed 74unsigned long newButtonTime; // debounce 75unsigned long oldButtonTime; // debounce 76unsigned long buttonTimeDifference; // debounce 77unsigned long debounceTime; // debounce 78int buttonGroup; // sets kinds of buttons on screen 79 80int currentScreen; // identifies current screen by adding x y and z 81int x; // for ones 82int y; // for tens 83int z; // for hundreds 84 85unsigned long backlightTimer; // for backlight timeout 86int backLightState; // status of backlight 1 for on and 0 for off 87unsigned long backlightTimeDifference; 88unsigned long newBacklightTime; 89unsigned long oldBacklightTime; 90 91char incomingMouthByte; 92char outgoingMouthByte; 93int mouthOnOffNew; 94int mouthOnOffOld; 95int mouthOnOffDifference; 96int mouthOnOffAdjusted; // value adjusted by 48 for ascii 97 98char incomingHeadByte; 99char outgoingHeadByte; 100int headOnOffNew; 101int headOnOffOld; 102int headOnOffDifference; 103int headOnOffAdjusted; // value adjusted by 48 for ascii 104 105//end declarations 106//end declarations 107//end declarations 108//end declarations 109//end declarations 110//end declarations 111//end declarations 112//end declarations 113//end declarations 114 115//********************************************************* 116//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 117//********************************************************* 118 119// begin void setup 120// begin void setup 121// begin void setup 122// begin void setup 123// begin void setup 124// begin void setup 125// begin void setup 126// begin void setup 127// begin void setup 128// begin void setup 129// begin void setup 130void setup() { 131Serial.begin(9600); 132Serial1.begin(9600); 133Serial2.begin(9600); 134 oldButtonTime = millis(); 135 newButtonTime = millis(); 136 Tft.TFTinit(); // init TFT library 137 TFT_BL_ON; // turn on the background light 138 backLightState = 1; 139 x = 0; 140 y = 0; 141 z = 0; 142 buttonPressed = 4; 143 buttonGroup = 0; 144 145 incomingHeadByte = 1; 146 outgoingHeadByte = 1; // for a bit more talkative serial data 147 headOnOffNew = 1; // stores head state from serial connection 148 headOnOffOld = 1; // stores head state from serial connection 149 150 151 incomingMouthByte = 0; 152 outgoingMouthByte = 0; // for a bit more talkative serial data 153 mouthOnOffNew = 1; // stores mouth state from serial connection 154 mouthOnOffOld = 1; // stores mouth state from serial connection 155 156 157 //////////////////////////////// 158 //// manually set variables //// 159 //////////////////////////////// 160 161 debounceTime = 1000; // button debounce in milliseconds 162 zMax = 460; // maximum pressure to detect 163 zMin = 100; // minimum pressure to detect 164 165 backlightTimer = 15000; // 5000 = 5 seconds for backlight timeout 166 167 168 currentScreen = 0; 169 callScreen(); 170 171} //void setup() 172// end void setup 173// end void setup 174// end void setup 175// end void setup 176// end void setup 177// end void setup 178// end void setup 179// end void setup 180 181//********************************************************* 182//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 183//********************************************************* 184 185// begin void loop 186// begin void loop 187// begin void loop 188// begin void loop 189// begin void loop 190// begin void loop 191// begin void loop 192// begin void loop 193// begin void loop 194// begin void loop 195// begin void loop 196// begin void loop 197// begin void loop 198// begin void loop 199 200void loop() { 201 202 tftBacklightTimeout(); // check time and turn off backlight 203 204 if(buttonGroup == 0){ // most regular pages 205 tftButtonGroup0(); // gather information from touch screen touches 206 buttonTimeDifference = newButtonTime - oldButtonTime; 207 if(debounceTime < buttonTimeDifference){ 208 whatScreen(); 209 callScreen(); 210 oldButtonTime = newButtonTime; 211 showStuff(); // serial prints 212 tftDisplay(); // display x y coordinates on tft display 213 } 214 } 215 if(buttonGroup == 1){ // on off buttons 216 tftButtonGroup1(); // gather information from touch screen touches 217 buttonTimeDifference = newButtonTime - oldButtonTime; 218 if(debounceTime < buttonTimeDifference){ 219 whatScreen(); 220 callScreen(); 221 oldButtonTime = newButtonTime; 222 showStuff(); // serial prints 223 tftDisplay(); // display x y coordinates on tft display 224 mouthUnoTxRx(); 225 } 226 } 227 if(buttonGroup == 2){ // head buttons 228 tftButtonGroup2(); // gather information from touch screen touches 229 buttonTimeDifference = newButtonTime - oldButtonTime; 230 if(debounceTime < buttonTimeDifference){ 231 whatScreen(); 232 callScreen(); 233 oldButtonTime = newButtonTime; 234 showStuff(); // serial prints 235 tftDisplay(); // display x y coordinates on tft display 236 headUnoTxRx(); 237 } 238 } 239 240 241} //void loop() 242 243// end of void loop 244// end of void loop 245// end of void loop 246// end of void loop 247// end of void loop 248// end of void loop 249// end of void loop 250// end of void loop 251// end of void loop 252// end of void loop 253// end of void loop 254// end of void loop 255// end of void loop 256// end of void loop 257// end of void loop 258 259//**************************************************************************************************** 260//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 261//**************************************************************************************************** 262///////////////////////////////////////////////////////////////////////////////////////////////////////// 263///////////////////////////////////////// functions /////////////////////////////////////////////////// 264///////////////////////////////////////////////////////////////////////////////////////////////////////// 265//**************************************************************************************************** 266//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 267//**************************************************************************************************** 268 269//--------------------------begin tftBacklightTimeout---------------------------------- 270void tftBacklightTimeout(){ 271 newBacklightTime = millis(); 272 if(backLightState = 0){ 273 backlightTimeDifference = newBacklightTime - oldBacklightTime; 274 if(backlightTimer > backlightTimeDifference){ 275 backlightTimeDifference = newBacklightTime - oldBacklightTime; 276 TFT_BL_ON; // turn on the background light 277 backLightState = 1; 278 oldBacklightTime = millis(); 279 } 280 } 281 if(backLightState = 1){ 282 backlightTimeDifference = newBacklightTime - oldBacklightTime; 283 if(backlightTimer < backlightTimeDifference){ 284 backlightTimeDifference = newBacklightTime - oldBacklightTime; 285 TFT_BL_OFF; // turn off the background light 286 backLightState = 0; 287 oldBacklightTime = millis(); 288 } 289 } 290} 291//--------------------------end tftBacklightTimeout---------------------------------- 292 293//**************************************************************************************************** 294//**************************************************************************************************** 295 296//--------------------------begin tftButtonGroup0---------------------------------- 297//--------------------------begin tftButtonGroup0---------------------------------- 298//--------------------------begin tftButtonGroup0---------------------------------- 299//--------------------------begin tftButtonGroup0---------------------------------- 300int tftButtonGroup0(){ 301 Point p = ts.getPoint(); 302 if(zMin<p.z && p.z<zMax){ 303 TFT_BL_ON; // turn on the background light 304 backLightState = 1; 305 oldBacklightTime = millis(); 306 newButtonTime = millis(); 307 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 308 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 309//Button 1 310 if(75<p.x && p.x<140){ 311 if(100<p.y && p.y<164){ 312 buttonPressed = 1; 313 } 314//Button 2 315 if(164<p.y && p.y<240){ 316 buttonPressed = 2; 317 } 318//Button 3 319 if(240<p.y && p.y<310){ 320 buttonPressed = 3; 321 } 322 } 323 } 324//Button 4 325 if(10<p.x && p.x<75){ 326 if(100<p.y && p.y<240){ 327 buttonPressed = 4; 328 } 329 } 330}//void tftButtonGroup0 331//--------------------------end tftButtonGroup0 code---------------------------------- 332//--------------------------end tftButtonGroup0 code---------------------------------- 333//--------------------------end tftButtonGroup0 code---------------------------------- 334//--------------------------end tftButtonGroup0 code---------------------------------- 335//--------------------------end tftButtonGroup0 code---------------------------------- 336//**************************************************************************************************** 337//**************************************************************************************************** 338 339//--------------------------begin tftButtonGroup1---------------------------------- 340//--------------------------begin tftButtonGroup1---------------------------------- 341//--------------------------begin tftButtonGroup1---------------------------------- 342//--------------------------begin tftButtonGroup1---------------------------------- 343int tftButtonGroup1(){ // for mouth 344buttonPressed = 0; 345 Point p = ts.getPoint(); 346 if(zMin<p.z && p.z<zMax){ 347 TFT_BL_ON; // turn on the background light 348 backLightState = 1; 349 oldBacklightTime = millis(); 350 newButtonTime = millis(); 351 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 352 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 353//Button 1 354 if(75<p.x && p.x<140){ 355 if(100<p.y && p.y<164){ 356 mouthOnOffNew = 1; // on 357 Serial.print("mouthOnOffNew set to "); 358 Serial.println(mouthOnOffNew); 359 } 360//Button 2 361 if(164<p.y && p.y<240){ 362 mouthOnOffNew = 2; // off 363 Serial.print("mouthOnOffNew set to "); 364 Serial.println(mouthOnOffNew); 365 } 366//Button 3 367// if(240<p.y && p.y<310){ 368// mouthOnOffNew = 3; // off 369// Serial.print("mouthOnOffNew set to "); 370// Serial.println(mouthOnOffNew); 371// } 372 } 373 } 374//Button 4 375 if(10<p.x && p.x<75){ 376 if(100<p.y && p.y<240){ 377 buttonPressed = 4; 378 buttonGroup = 0; 379 } 380 } 381}//void tftButtonGroup1 382//--------------------------end tftButtonGroup1 code---------------------------------- 383//--------------------------end tftButtonGroup1 code---------------------------------- 384//--------------------------end tftButtonGroup1 code---------------------------------- 385//--------------------------end tftButtonGroup1 code---------------------------------- 386//--------------------------end tftButtonGroup1 code---------------------------------- 387//**************************************************************************************************** 388//**************************************************************************************************** 389 390//--------------------------begin tftButtonGroup2---------------------------------- 391//--------------------------begin tftButtonGroup2---------------------------------- 392//--------------------------begin tftButtonGroup2---------------------------------- 393//--------------------------begin tftButtonGroup2---------------------------------- 394int tftButtonGroup2(){ // for mouth 395buttonPressed = 0; 396 Point p = ts.getPoint(); 397 if(zMin<p.z && p.z<zMax){ 398 TFT_BL_ON; // turn on the background light 399 backLightState = 1; 400 oldBacklightTime = millis(); 401 newButtonTime = millis(); 402 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 403 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 404//Button 1 405 if(75<p.x && p.x<140){ 406 if(100<p.y && p.y<164){ 407 headOnOffNew = 1; // on 408 Serial.print("headOnOffNew set to "); 409 Serial.println(headOnOffNew); 410 } 411//Button 2 412 if(164<p.y && p.y<240){ 413 headOnOffNew = 2; // off 414 Serial.print("headOnOffNew set to "); 415 Serial.println(headOnOffNew); 416 } 417//Button 3 418// if(240<p.y && p.y<310){ 419// buttonPressed = 3; 420// } 421 } 422 } 423//Button 4 424 if(10<p.x && p.x<75){ 425 if(100<p.y && p.y<240){ 426 buttonPressed = 4; 427 buttonGroup = 0; 428 } 429 } 430}//void tftButtonGroup2 431//--------------------------end tftButtonGroup2 code---------------------------------- 432//--------------------------end tftButtonGroup2 code---------------------------------- 433//--------------------------end tftButtonGroup2 code---------------------------------- 434//--------------------------end tftButtonGroup2 code---------------------------------- 435//--------------------------end tftButtonGroup2 code---------------------------------- 436//**************************************************************************************************** 437//**************************************************************************************************** 438 439//--------------------------begin mouthUnoTxRx---------------------------------- 440 441void mouthUnoTxRx(){ 442 if(mouthOnOffNew != mouthOnOffOld){ 443 Serial.println("starting txrx"); 444 if(mouthOnOffNew == 1){ 445 Serial.println("Starting tx"); 446 Serial1.flush(); 447 Serial1.write('1'); 448 mouthOnOffOld = 1; 449//begin rx 450 Serial.println("Starting rx"); 451 452 delay(10); // tweak delay to accomodate uno 453 454 // use a serial available after flush funtion while or for loop or interrrupt or somethin 455 incomingMouthByte = Serial1.read(); 456 Serial1.flush(); 457 mouthOnOffAdjusted = incomingMouthByte; 458 Serial.print("mouthOnOffAdjusted should be 1: "); 459 Serial.println(mouthOnOffAdjusted); 460 } 461 if(mouthOnOffNew == 2){ 462 Serial.println("Starting tx"); 463 Serial1.flush(); 464 Serial1.write('2'); 465 mouthOnOffOld = 2; 466//begin rx 467 Serial.println("Starting rx"); 468 469 delay(10); // tweak delay to accomodate uno 470 471 incomingMouthByte = Serial1.read(); 472 Serial1.flush(); 473 mouthOnOffAdjusted = incomingMouthByte; 474 Serial.print("mouthOnOffAdjusted should be 2: "); 475 Serial.println(mouthOnOffAdjusted); 476 } 477 if(mouthOnOffNew == 3){ 478 Serial.println("Starting tx"); 479 Serial1.flush(); 480 Serial1.write('3'); 481 mouthOnOffOld = 3; 482//begin rx 483 Serial.println("Starting rx"); 484 485 delay(10); // tweak delay to accomodate uno 486 487 // use a serial available after flush funtion while or for loop or interrrupt or somethin 488 incomingMouthByte = Serial1.read(); 489 Serial1.flush(); 490 mouthOnOffAdjusted = incomingMouthByte; 491 Serial.print("mouthOnOffAdjusted should be 3: "); 492 Serial.println(mouthOnOffAdjusted); 493 } 494 if(mouthOnOffNew == 4){ 495 Serial.println("Starting tx"); 496 Serial1.flush(); 497 Serial1.write('4'); 498 mouthOnOffOld = 4; 499//begin rx 500 Serial.println("Starting rx"); 501 502 delay(10); // tweak delay to accomodate uno 503 504 // use a serial available after flush funtion while or for loop or interrrupt or somethin 505 incomingMouthByte = Serial1.read(); 506 Serial1.flush(); 507 mouthOnOffAdjusted = incomingMouthByte; 508 Serial.print("mouthOnOffAdjusted should be 4: "); 509 Serial.println(mouthOnOffAdjusted); 510 } 511 512 513 else if(mouthOnOffAdjusted <= 1 && 4 >= mouthOnOffAdjusted){ 514 Serial.println("error reply wasn't like expected"); 515 Serial.print("instead, the adjusted reply was"); 516 517 delay(10); // tweak delay to accomodate uno 518 519 incomingMouthByte = Serial1.read(); 520 Serial1.flush(); 521 mouthOnOffAdjusted = incomingMouthByte; 522 Serial.print("mouthOnOffAdjusted: "); 523 Serial.println(mouthOnOffAdjusted); 524 } 525 } 526 else if(mouthOnOffOld = mouthOnOffNew){ 527 } 528 Serial.flush(); 529 Serial1.flush(); 530} 531 532//--------------------------end mouthUnoTxRx -------------------------------------- 533//-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- 534//--------------------------begin headUnoTxRx---------------------------------- 535 536void headUnoTxRx(){ 537 if(headOnOffNew != headOnOffOld){ 538 Serial.println("starting txrx"); 539 if(headOnOffNew == 1){ 540 Serial.println("Starting tx"); 541 Serial2.flush(); 542 Serial2.write('1'); 543 headOnOffOld = 1; 544//begin rx 545 Serial.println("Starting rx"); 546 547 delay(10); // tweak delay to accomodate uno 548 549 // use a serial available after flush funtion while or for loop or interrrupt or somethin instead of delay 550 incomingHeadByte = Serial2.read(); 551 Serial2.flush(); 552 headOnOffAdjusted = incomingHeadByte; 553 Serial.print("headOnOffAdjusted should be 1: "); 554 Serial.println(headOnOffAdjusted); 555 } 556 if(headOnOffNew == 2){ 557 Serial.println("Starting tx"); 558 Serial2.flush(); 559 Serial2.write('2'); 560 headOnOffOld = 2; 561//begin rx 562 Serial.println("Starting rx"); 563 564 delay(10); // tweak delay to accomodate uno 565 566 incomingHeadByte = Serial2.read(); 567 Serial2.flush(); 568 headOnOffAdjusted = incomingHeadByte; 569 Serial.print("headOnOffAdjusted should be 2: "); 570 Serial.println(headOnOffAdjusted); 571 } 572 else if(headOnOffAdjusted != 1 && headOnOffAdjusted != 2){ 573 Serial.println("error reply wasn't like expected"); 574 Serial.print("instead, the adjusted reply was"); 575 576 delay(10); // tweak delay to accomodate uno 577 578 incomingHeadByte = Serial2.read(); 579 Serial2.flush(); 580 headOnOffAdjusted = incomingHeadByte; 581 Serial.print("headOnOffAdjusted: "); 582 Serial.println(headOnOffAdjusted); 583 } 584 } 585 else if(headOnOffOld = headOnOffNew){ 586 } 587 Serial.flush(); 588 Serial2.flush(); 589} 590 591//--------------------------end headUnoTxRx -------------------------------------- 592//**************************************************************************************************** 593//**************************************************************************************************** 594 595//--------------------------begin tftDisplay code---------------------------------- 596void tftDisplay(){ 597 Point p = ts.getPoint(); 598 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 599 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 600 601 Tft.fillRectangle(70, 100, 60, 30, BLACK); 602 Tft.drawNumber((buttonGroup), 70, 100, 3, GREEN); 603 Tft.fillRectangle(140, 100, 60, 30, BLACK); 604 Tft.drawNumber((mouthOnOffNew), 140, 100, 3, GREEN); 605 Tft.fillRectangle(160, 100, 60, 30, BLACK); 606 Tft.drawNumber((headOnOffNew), 160, 100, 3, GREEN); 607 Tft.fillRectangle(0, 225, 60, 30, BLACK); 608 Tft.drawNumber((p.x), 0, 225, 3, GREEN); 609 Tft.fillRectangle(180, 225, 60, 30, BLACK); 610 Tft.drawNumber((p.y), 180, 225, 3, GREEN); 611 Tft.fillRectangle(100, 225, 60, 30, BLACK); 612 Tft.drawNumber((buttonPressed), 100, 225, 3, GREEN); 613 Tft.fillRectangle(120, 290, 60, 30, BLACK); 614 Tft.drawNumber((currentScreen), 120, 290, 3, GREEN); 615 616 617}// void tftDisplay 618//--------------------------end tftDisplay code------------------------------------ 619 620//**************************************************************************************************** 621//**************************************************************************************************** 622 623//-------------------------- begin mouth on off function -------------------------- 624//-------------------------- end mouth on off function -------------------------- 625 626//**************************************************************************************************** 627//**************************************************************************************************** 628 629//-------------------------- begin head on off function -------------------------- 630//-------------------------- end head on off function ------------------------- 631 632//**************************************************************************************************** 633//**************************************************************************************************** 634 635//-------------------------- begin serial display function -------------------------- 636void showStuff(){ 637 Serial.println("------/ last update /-------"); 638// Serial.println("------begin display-------"); 639 Serial.print("buttonPressed "); 640 Serial.println(buttonPressed); 641 Serial.print("x "); 642 Serial.println(x); 643 Serial.print("y "); 644 Serial.println(y); 645 Serial.print("z "); 646 Serial.println(z); 647 Serial.print("currentScreen "); 648 Serial.println(currentScreen); 649// Serial.println("-------end display--------"); 650 Serial.println(""); 651 Serial.println(""); 652 Serial.println(""); 653 } 654//-------------------------- end serial display function ------------------------- 655 656 657//**************************************************************************************************** 658//**************************************************************************************************** 659 660//--------------------------- Primary screen maps -------------------------------- 661/* 662******** 663updates needed 664******** 6651 ditch the contrast 6662 ditch the brightness 6673 setup screen timeout 668 669 670 671 672screen 0000 A)Central Command 673 674 screen 0001 a)motor controls 675 676 screen 0001 b) Touch Screen Timeout 677 screen 0011 -longer 678 screen 0011 -shorter 679 screen 0011 -reset 680 681 screen 0001 c)sensor monitors 682 screen 0021 -head reports 683 screen 0121 *report pir detection 684 screen 0121 *report pot position 685 screen 0021 -mouth reports 686 screen 0221 *graves sense 687 screen 0221 *echo sense 688 screen 0221 *report mouth servo position 689// screen 0221 *adjust sensitivity? 690 691screen 0000 B)Mouth Control 692 693 screen 0002 a)test button 694 screen 0012 -open 695 screen 0012 -close 696 697 screen 0002 b)sound sensors on/off 698 699 screen 0022 -echo sense 700 screen 0122 *on 701 screen 0122 *off 702 screen 0122 *monitor sensor 703 704 screen 0022 -graves sense 705 screen 0222 *on 706 screen 0222 *off 707 screen 0222 *monitor sensors 708 709 screen 0002 c)sound sensor status 710 screen 0032 -echo 711 screen 0032 -graves 712 713screen 0000 C)Head Control 714 screen 0003 a)head motor on/off 715 screen 0013 -on 716 screen 0013 -off 717 screen 0003 b)manual point 718 screen 0023 -slider 719 ---/\ 720ew screens/\\--- 721 722 ---\\/old screens\\/--- 723 screen 0000 A)Home 724 screen 0001 a)settings 725 screen 0011 -brightness 726 screen 0011 -contrast 727 screen 0011 -screen lock time out 728 screen 0001 b)sensor monitors 729 screen 0021 -pir 730 screen 0121 *report pir detection 731 screen 0021 -sound 732 screen 0221 *sense echo sound 733 screen 0221 *sense graves sound 734 screen 0221 *report mouth servo position 735 screen 0221 *adjust sensitivity? 736 screen 0021 -head potentiometer 737 screen 0021 -bluetooth 738 screen 0001 c)bluetooth 739 screen 0031 -on 740 screen 0031 -off 741 screen 0031 -monitor 742screen 0000 B)Mouth Control 743 screen 0002 a)test button 744 screen 0012 -open 745 screen 0012 -close 746 screen 0012 -push button chicken switch 747 screen 0002 b)sound sensors on/off 748 screen 0022 -echo sense 749 screen 0122 *on 750 screen 0122 *off 751 screen 0122 *monitor sensor 752 screen 0022 -graves sense 753 screen 0222 *on 754 screen 0222 *off 755 screen 0222 *monitor sensors 756 screen 0002 c)sound sensor status 757 screen 0032 -echo 758 screen 0032 -graves 759screen 0000 C)Head Control 760 screen 0003 a)pir on/off 761 screen 0013 -on 762 screen 0013 -off 763 screen 0013 -sensor 764 screen 0003 b)manual point 765 screen 0023 -slider 766*/ 767//**************************************************************************************************** 768//**************************************************************************************************** 769//-------------------------- begin whatScreen function ------------------------- 770//-------------------------- begin whatScreen function ------------------------- 771//-------------------------- begin whatScreen function ------------------------- 772//-------------------------- begin whatScreen function ------------------------- 773 774int whatScreen(){ 775 if(x == 0){ 776 if(buttonPressed == 1){ 777 x = x + 1; 778 Serial.println("x + 1"); 779 } 780 if(buttonPressed == 2){ 781 x = x + 2; 782 Serial.println("x + 2"); 783 } 784 if(buttonPressed == 3){ 785 x = x + 3; 786 Serial.println("x + 3"); 787 } 788 if(buttonPressed == 4){ 789 x = 0; 790 Serial.println("x = 0"); 791 } 792 if(buttonPressed == 5){ 793 x = 0; 794 y = 0; 795 z = 0; 796 Serial.println("xyz all 0"); 797 } 798 } 799 else if(x >> 0){ 800 if(y == 0){ 801 if(buttonPressed == 1){ 802 y = y + 10; 803 Serial.println("y + 10"); 804 } 805 if(buttonPressed == 2){ 806 y = y + 20; 807 Serial.println("y + 20"); 808 } 809 if(buttonPressed == 3){ 810 y = y + 30; 811 Serial.println("y + 30"); 812 } 813 if(buttonPressed == 4){ 814 x = 0; 815 Serial.println("x = 0"); 816 } 817 if(buttonPressed == 5){ 818 x = 0; 819 y = 0; 820 z = 0; 821 Serial.println("xyz all 0"); 822 } 823 } 824 else if (y >> 0){ 825 if(buttonPressed == 1){ 826 z = z + 100; 827 Serial.println("z + 100"); 828 } 829 if(buttonPressed == 2){ 830 z = z + 200; 831 Serial.println("z + 200"); 832 } 833 if(buttonPressed == 3){ 834 z = z + 300; 835 Serial.println("z + 300"); 836 } 837 if(buttonPressed == 4){ 838 if(z == 0){ 839 y = 0; 840 Serial.println("y = 0"); 841 } 842 else if(z >> 0){ 843 z = 0; 844 Serial.println("z = 0"); 845 } 846 } 847 if(buttonPressed == 5){ 848 x = 0; 849 y = 0; 850 z = 0; 851 Serial.println("xyz all 0"); 852 } 853 }//y>0 854 }//x>0 855 currentScreen = z+y+x; 856 857 858//================button group exceptions================ 859//================button group exceptions================ 860 if(currentScreen == 122){ 861 buttonGroup=1; 862 } 863 if(currentScreen == 222){ 864 buttonGroup=1; 865 } 866 if(currentScreen == 23){ 867 buttonGroup=2; 868 } 869//================button group exceptions================ 870//================button group exceptions================ 871 872} 873//-------------------------- end whatScreen function ------------------------- 874//-------------------------- end whatScreen function ------------------------- 875//-------------------------- end whatScreen function ------------------------- 876//-------------------------- end whatScreen function ------------------------- 877//-------------------------- end whatScreen function ------------------------- 878 879//**************************************************************************************************** 880//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 881//**************************************************************************************************** 882//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 883//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 884//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 885//**************************************************************************************************** 886//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 887//**************************************************************************************************** 888 889//-------------------------- begin callScreen function ------------------------- 890//-------------------------- begin callScreen function ------------------------- 891//-------------------------- begin callScreen function ------------------------- 892//-------------------------- begin callScreen function ------------------------- 893//-------------------------- begin callScreen function ------------------------- 894//-------------------------- begin callScreen function ------------------------- 895//-------------------------- begin callScreen function ------------------------- 896//-------------------------- begin callScreen function ------------------------- 897//-------------------------- begin callScreen function ------------------------- 898//-------------------------- begin callScreen function ------------------------- 899//-------------------------- begin callScreen function ------------------------- 900 901int callScreen(){ 902 Tft.fillRectangle(0, 0, 240, 320, BLACK); 903 904//<><><><><><><><><><><><><><><><><><><><><><><><> 905//<><><><><><><><> begin screen 0000 master <><><><><><><><> 906//<><><><><><><><><><><><><><><><><><><><><><><><> 907if(currentScreen == 0){ 908 // " " 909 Tft.drawString("GRAVES",0,5,4, GREEN); 910 Tft.drawString("INTERFACE",10,50,4,GREEN); 911 Tft.drawString("Main Controls", 80,130, 3, GREEN); 912 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 913 Tft.drawString("Head Control", 10, 260, 3, GREEN); 914} 915//<><><><><><><><><><><><><><><><><><><><><><><><> 916//<><><><><><><><> end screen 0000 master <><><><><><><><><> 917//<><><><><><><><><><><><><><><><><><><><><><><><> 918 919//<><><><><><><><><><><><><><><><><><><><><><><><> 920//<><><><><><><><> begin screen 0001 <><><><><><><><> 921//<><><><><><><><><><><><><><><><><><><><><><><><> 922 if(currentScreen == 1){ 923 // " " 924 Tft.drawString("SETTINGS",00,5,4,BLUE); 925 Tft.drawString("FOR THINGS",00,50,4,BLUE); 926 Tft.drawString("Motors Power", 10,130, 3, BLUE); 927 Tft.drawString("Sensors", 20, 195, 3, BLUE); 928 Tft.drawString("Light Timeout", 00, 260, 3, BLUE); 929 Tft.drawString("<", 0, 160, 3, GREEN); // back button 930} 931//<><><><><><><><><><><><><><><><><><><><><><><><> 932//<><><><><><><><> end screen 0001 <><><><><><><><><> 933//<><><><><><><><><><><><><><><><><><><><><><><><> 934 935//<><><><><><><><><><><><><><><><><><><><><><><><> 936//<><><><><><><><> begin screen 0011 <><><><><><><><> 937//<><><><><><><><><><><><><><><><><><><><><><><><> 938 if(currentScreen == 11){ 939 // " " 940 Tft.drawString("BACKLIGHT",00,5,4,BLUE); 941 Tft.drawString("TIME OUT",10,50,4,YELLOW); 942 Tft.drawString("Increase", 80,130, 3, BLUE); 943 Tft.drawString("Decrease", 05, 195, 3, GREEN); 944 Tft.drawString("Reset", 10, 260, 3, GREEN); 945 Tft.drawString("<", 0, 160, 3, GREEN); // back button 946} 947 948//<><><><><><><><><><><><><><><><><><><><><><><><> 949//<><><><><><><><> end screen 0011 <><><><><><><><><> 950//<><><><><><><><><><><><><><><><><><><><><><><><> 951 952//<><><><><><><><><><><><><><><><><><><><><><><><> 953//<><><><><><><><> begin screen 0021 <><><><><><><><> 954//<><><><><><><><><><><><><><><><><><><><><><><><> 955 if(currentScreen == 21){ 956 // " " 957 Tft.drawString("INCOMING",00,5,4,BLUE); 958 Tft.drawString("SENSOR DATA",10,50,4,YELLOW); 959 Tft.drawString("Head Sensors", 80,130, 3, BLUE); 960 Tft.drawString("Mouth Sensors", 05, 195, 3, GREEN); 961// Tft.drawString("Head Position", 10, 260, 3, GREEN); 962// Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 963 Tft.drawString("<", 0, 160, 3, GREEN); // back button 964} 965//<><><><><><><><><><><><><><><><><><><><><><><><> 966//<><><><><><><><> end screen 0021 <><><><><><><><><> 967//<><><><><><><><><><><><><><><><><><><><><><><><> 968 969//<><><><><><><><><><><><><><><><><><><><><><><><> 970//<><><><><><><><> begin screen 0121 <><><><><><><><> 971//<><><><><><><><><><><><><><><><><><><><><><><><> 972 if(currentScreen == 121){ 973 // " " 974 Tft.drawString("HEAD",0,5,4,BLUE); 975 Tft.drawString("SENSORS",10,50,4,YELLOW); 976 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 977 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 978 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 979 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 980 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 981 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 982 Tft.drawString("<", 0, 160, 3, GREEN); // back button 983} 984//<><><><><><><><><><><><><><><><><><><><><><><><> 985//<><><><><><><><> end screen 0121 <><><><><><><><><> 986//<><><><><><><><><><><><><><><><><><><><><><><><> 987 988//<><><><><><><><><><><><><><><><><><><><><><><><> 989//<><><><><><><><> begin screen 0221 <><><><><><><><> 990//<><><><><><><><><><><><><><><><><><><><><><><><> 991 if(currentScreen == 221){ 992 // " " 993 Tft.drawString("MOUTH",0,5,4,BLUE); 994 Tft.drawString("SENSORS",10,50,4,YELLOW); 995 Tft.drawString("Echo Sense", 05, 195, 3, GREEN); 996 Tft.drawString("Servo Position", 10, 260, 3, GREEN); 997 Tft.drawString("<", 0, 160, 3, GREEN); // back button 998} 999//<><><><><><><><><><><><><><><><><><><><><><><><> 1000//<><><><><><><><> end screen 0221 <><><><><><><><><> 1001//<><><><><><><><><><><><><><><><><><><><><><><><> 1002 1003//<><><><><><><><><><><><><><><><><><><><><><><><> 1004//<><><><><><><><> begin screen 0031 <><><><><><><><> 1005//<><><><><><><><><><><><><><><><><><><><><><><><> 1006 if(currentScreen == 31){ 1007 // " " 1008 Tft.drawString("Bluetooth",0,5,4,BLUE); 1009 Tft.drawString("Control",10,50,4,YELLOW); 1010 Tft.drawString("On", 80,130, 3, BLUE); 1011 Tft.drawString("Off", 05, 195, 3, GREEN); 1012 Tft.drawString("Monitor", 10, 260, 3, GREEN); 1013 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1014} 1015//<><><><><><><><><><><><><><><><><><><><><><><><> 1016//<><><><><><><><> end screen 0031 <><><><><><><><><> 1017//<><><><><><><><><><><><><><><><><><><><><><><><> 1018 1019//<><><><><><><><><><><><><><><><><><><><><><><><> 1020//<><><><><><><><> begin screen 0002 <><><><><><><><> 1021//<><><><><><><><><><><><><><><><><><><><><><><><> 1022 if(currentScreen == 2){ 1023 // " " 1024 Tft.drawString("Mouth",0,5,4,BLUE); 1025 Tft.drawString("Control",10,50,4,YELLOW); 1026 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 1027 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 1028 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1029 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1030 } 1031//<><><><><><><><><><><><><><><><><><><><><><><><> 1032//<><><><><><><><> end screen 0002 <><><><><><><><><> 1033//<><><><><><><><><><><><><><><><><><><><><><><><> 1034 1035 1036//<><><><><><><><><><><><><><><><><><><><><><><><> 1037//<><><><><><><><> begin screen 0012 <><><><><><><><> 1038//<><><><><><><><><><><><><><><><><><><><><><><><> 1039 if(currentScreen == 12){ 1040 // " " 1041 Tft.drawString("JAW TEST",0,5,4,BLUE); 1042 Tft.drawString("OPERATION",10,50,4,YELLOW); 1043 Tft.drawString("Open", 80,130, 3, BLUE); 1044 Tft.drawString("Close", 05, 195, 3, GREEN); 1045// Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 1046 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1047} 1048//<><><><><><><><><><><><><><><><><><><><><><><><> 1049//<><><><><><><><> end screen 0012 <><><><><><><><><> 1050//<><><><><><><><><><><><><><><><><><><><><><><><> 1051 1052 1053//<><><><><><><><><><><><><><><><><><><><><><><><> 1054//<><><><><><><><> begin screen 0022 <><><><><><><><> 1055//<><><><><><><><><><><><><><><><><><><><><><><><> 1056 if(currentScreen == 22){ 1057 // " " 1058 Tft.drawString("SOUND SENSOR",0,5,4,BLUE); 1059 Tft.drawString("SELECTION",10,50,4,YELLOW); 1060 Tft.drawString("echo Sense", 80,130, 3, BLUE); 1061 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 1062 Tft.drawString("Monitor Both", 10, 260, 3, GREEN); 1063 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1064} 1065//<><><><><><><><><><><><><><><><><><><><><><><><> 1066//<><><><><><><><> end screen 0022 <><><><><><><><><> 1067//<><><><><><><><><><><><><><><><><><><><><><><><> 1068 1069 1070 1071//<><><><><><><><><><><><><><><><><><><><><><><><> 1072//<><><><><><><><> begin screen 0122 <><><><><><><><> 1073//<><><><><><><><><><><><><><><><><><><><><><><><> 1074 if(currentScreen == 122){ 1075 // " " 1076 Tft.drawString("ECHO SENSOR",0,5,4,BLUE); 1077 Tft.drawString("MONITOR",10,50,4,YELLOW); 1078 Tft.drawString("", 120, 130, 3, GREEN); 1079 Tft.drawString("", 115, 195, 3, RED); 1080 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1081 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1082} 1083//<><><><><><><><><><><><><><><><><><><><><><><><> 1084//<><><><><><><><> end screen 0122 <><><><><><><><><> 1085//<><><><><><><><><><><><><><><><><><><><><><><><> 1086 1087//<><><><><><><><><><><><><><><><><><><><><><><><> 1088//<><><><><><><><> begin screen 0222 <><><><><><><><> 1089//<><><><><><><><><><><><><><><><><><><><><><><><> 1090 if(currentScreen == 222){ 1091 // " " 1092 Tft.drawString("GRAVES SENSOR",0,5,4,BLUE); 1093 Tft.drawString("MONITOR",10,50,4,YELLOW); 1094 Tft.drawString("", 120, 130, 3, GREEN); 1095 Tft.drawString("", 115, 195, 3, RED); 1096 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 1097 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1098} 1099//<><><><><><><><><><><><><><><><><><><><><><><><> 1100//<><><><><><><><> end screen 0222 <><><><><><><><><> 1101//<><><><><><><><><><><><><><><><><><><><><><><><> 1102 1103//<><><><><><><><><><><><><><><><><><><><><><><><> 1104//<><><><><><><><> begin screen 0032 <><><><><><><><> 1105//<><><><><><><><><><><><><><><><><><><><><><><><> 1106 if(currentScreen == 32){ 1107 // " " 1108 Tft.drawString("ECHO & GRAVES",0,5,4,BLUE); 1109 Tft.drawString("SENSORS",10,50,4,YELLOW); 1110 Tft.drawString("echo", 80,130, 3, BLUE); 1111 Tft.drawString("Graves", 05, 195, 3, GREEN); 1112 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1113} 1114//<><><><><><><><><><><><><><><><><><><><><><><><> 1115//<><><><><><><><> end screen 0032 <><><><><><><><><> 1116//<><><><><><><><><><><><><><><><><><><><><><><><> 1117 1118//<><><><><><><><><><><><><><><><><><><><><><><><> 1119//<><><><><><><><> begin screen 0003 <><><><><><><><> 1120//<><><><><><><><><><><><><><><><><><><><><><><><> 1121 if(currentScreen == 3){ 1122 // " " 1123 Tft.drawString("Head Control",0,5,4,BLUE); 1124 Tft.drawString("Operations",10,50,4,YELLOW); 1125 Tft.drawString("PIR Array", 80,130, 3, BLUE); 1126 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 1127 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 1128 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1129} 1130//<><><><><><><><><><><><><><><><><><><><><><><><> 1131//<><><><><><><><> end screen 0003 <><><><><><><><><> 1132//<><><><><><><><><><><><><><><><><><><><><><><><> 1133 1134//<><><><><><><><><><><><><><><><><><><><><><><><> 1135//<><><><><><><><> begin screen 0013 <><><><><><><><> 1136//<><><><><><><><><><><><><><><><><><><><><><><><> 1137 if(currentScreen == 13){ 1138 // " " 1139 Tft.drawString("HEAD MOTOR",0,5,4,BLUE); 1140 Tft.drawString("CONTROL",10,50,4,YELLOW); 1141 Tft.drawString("On", 80,130, 3, BLUE); 1142 Tft.drawString("Off", 05, 195, 3, GREEN); 1143 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 1144 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1145} 1146//<><><><><><><><><><><><><><><><><><><><><><><><> 1147//<><><><><><><><> end screen 0013 <><><><><><><><><> 1148//<><><><><><><><><><><><><><><><><><><><><><><><> 1149 1150//<><><><><><><><><><><><><><><><><><><><><><><><> 1151//<><><><><><><><> begin screen 0023 <><><><><><><><> 1152//<><><><><><><><><><><><><><><><><><><><><><><><> 1153 if(currentScreen == 23){ 1154 // " " 1155 Tft.drawString("GRAVES HEAD",0,5,3,BLUE); 1156 Tft.drawString("POINTER",10,50,3,YELLOW); 1157 Tft.drawString("Left", 120, 130, 3, GREEN); 1158 Tft.drawString("Right", 115, 195, 3, RED); 1159 Tft.drawString("Center", 10, 260, 3, GREEN); 1160 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1161} 1162//<><><><><><><><><><><><><><><><><><><><><><><><> 1163//<><><><><><><><> end screen 0023 <><><><><><><><><> 1164//<><><><><><><><><><><><><><><><><><><><><><><><> 1165 1166 1167//<><><><><><><><><><><><><><><><><><><><><><><><> 1168//<><><><><><><><> begin screen 0422 <><><><><><><><> 1169//<><><><><><><><><><><><><><><><><><><><><><><><> 1170 if(currentScreen == 422){ 1171 // " " 1172 Tft.drawString("Command Sent",0,5,3,BLUE); 1173 Tft.drawString("Press Back to",0,55,3,YELLOW); 1174 Tft.drawString("Contiue", 50,105, 3, BLUE); 1175 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1176} 1177//<><><><><><><><><><><><><><><><><><><><><><><><> 1178//<><><><><><><><> end screen 0422 <><><><><><><><><> 1179//<><><><><><><><><><><><><><><><><><><><><><><><> 1180 1181 1182////<><><><><><><><><><><><><><><><><><><><><><><><> 1183////<><><><><><><><> begin screen lost <><><><><><><><> 1184////<><><><><><><><><><><><><><><><><><><><><><><><> 1185// else if(currentScreen){ 1186// // " " 1187// Tft.drawString("Screen not",0,5,3,BLUE); 1188// Tft.drawString("found. Please",40,50,3,YELLOW); 1189// Tft.drawString("use the back", 80,130, 3, BLUE); 1190// Tft.drawString("button to", 05, 195, 3, GREEN); 1191// Tft.drawString("return to fun", 10, 260, 3, GREEN); 1192// Tft.drawString("<", 0, 160, 3, GREEN); // back button 1193//} 1194////<><><><><><><><><><><><><><><><><><><><><><><><> 1195////<><><><><><><><> end screen lost <><><><><><><><><> 1196////<><><><><><><><><><><><><><><><><><><><><><><><> 1197 1198}// callScreen 1199//-------------------------- end callScreen function ------------------------- 1200//-------------------------- end callScreen function ------------------------- 1201//-------------------------- end callScreen function ------------------------- 1202//-------------------------- end callScreen function ------------------------- 1203//-------------------------- end callScreen function ------------------------- 1204//-------------------------- end callScreen function ------------------------- 1205//-------------------------- end callScreen function ------------------------- 1206//-------------------------- end callScreen function ------------------------- 1207//-------------------------- end callScreen function ------------------------- 1208//-------------------------- end callScreen function ------------------------- 1209//-------------------------- end callScreen function ------------------------- 1210//-------------------------- end callScreen function ------------------------- 1211//-------------------------- end callScreen function ------------------------- 1212 1213 1214//**************************************************************************************************** 1215//**************************************************************************************************** 1216 1217 1218 1219 1220 1221 1222 1223//**************************************************************************************************** 1224//**************************************************************************************************** 1225 1226// fin
19102018 they are playing well together
c_cpp
I updated dc bias circuit schematic. The uno mouth code is more or less done for now. It receives commands and echos back. It gives led fast or slow flash without using delay commands to signify if uno is executing functions or waiting for an on command. The single sound input will be relatively easy to duplicate for a second input for mouth movements. The second dc bias circuit is also ready along with a line tap wire made from a headphone/aux cord. The serial functions in this sketch are the same as the head sketch.
1/* 2last edit Friday oct 19 2018 3 4gravesunomouth 5 6graves 7 project 8arduino Uno 9Slave 1 10coded from scratch by wylie jones 11wyliejones@gmail.com 12 13Graves 14 multi arduino build 10/2018 15Arduino mega 2560 with 240/320 tft and micro sd card 16 (for storing screen backgrounds) 17two arduino uno's 18slave1 arduino uno to sense 19 sound from graves and echo dot to control mouth 20slave2 arduino uno to control 21 passive sensor array and head servo 22 23sound is sensed with a simple DC bias 24 circuit to capture line level input to be used as a digital signal 25 26 analogue 27 pin speaker + 28 \(yellow signal / 29 (red from speaker) 30 \ wire) / 31 \\ 32 / 33 *--------[=]-----------*---------[=]----------* 34 35 | resistor \ resistor | 36 | \\ 37 | 38 |(red with white) \ |to arduino 39 ground (black with white) 40to arduino 5v+ speaker - 41 (black 42 from speaker) 43 44*/ 45#include <Servo.h> 46#include <SPI.h> 47 48//---------------------begin 49 declarations----------------------- 50// for servo actions 51Servo mouthServo; 52 53// 54 for gathering and mapping sound data 55int soundPin=A5; // incoming lead from dc 56 bias circuit 57int soundDetected; // stores value from sound pin 58int soundLevel; 59 // converted values that only include 512-1024 60int soundMap; // conversion from 61 512-1024 to 0-255 62int servoMap; // conversion from 0-255 to 100-70 63 64// 65 communication 66char incomingMouthByte; // for incoming serial data 67char outgoingMouthByte; // 68 for a bit more talkative serial data 69int mouthOnOffNew; // stores mouth state 70 from serial connection 71int mouthOnOffOld; // stores mouth state from serial connection 72int 73 mouthOnOffAdjusted; // value adjusted by 48 for ascii 74 75// for blinking 76const 77 int ledPin = LED_BUILTIN;// the number of the LED pin 78int ledState = LOW; // 79 ledState used to set the LED 80unsigned long previousMillis = 0; // will 81 store last time LED was updated 82//---------------------end declarations----------------------- 83//********************************************************* 84//********************************************************* 85//---------------------begin 86 void setup----------------------- 87//---------------------begin void setup----------------------- 88//---------------------begin 89 void setup----------------------- 90void setup(){ 91 delay(5000); 92 Serial.begin(9600); 93 94 mouthServo.attach(6); 95 incomingMouthByte = 0; // for incoming serial data 96 97 outgoingMouthByte = 0; // for a little more talkative serial data 98 mouthOnOffNew 99 = 1; // stores mouth state from serial connection 100 mouthOnOffOld = 1; // stores 101 mouth state from serial connection 102 pinMode(ledPin, OUTPUT); 103} 104//---------------------end 105 void setup----------------------- 106//---------------------end void setup----------------------- 107//---------------------end 108 void setup----------------------- 109//********************************************************** 110//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 111//********************************************************** 112//---------------------begin 113 void loop----------------------- 114//---------------------begin void loop----------------------- 115//---------------------begin 116 void loop----------------------- 117void loop(){ 118 serialDoStuff(); 119 if(mouthOnOffNew 120 == mouthOnOffOld){ 121 if(mouthOnOffNew == 1){ 122 blinkFast(); 123 124 mouthDoStuff(); 125 } 126 if(mouthOnOffNew == 2){ 127 blinkSlow(); 128 129 } 130 } 131 else if(mouthOnOffNew != mouthOnOffOld){ 132 mouthOnOffNew 133 = mouthOnOffOld; 134 } 135} 136//---------------------end void loop----------------------- 137//---------------------end 138 void loop----------------------- 139//---------------------end void loop----------------------- 140//********************************************************* 141//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 142//********************************************************* 143//---------------------begin 144 serialDoStuff ----------------- 145void serialDoStuff(){ 146 if(Serial.available() 147 > 0){ 148 incomingMouthByte = Serial.read(); 149 mouthOnOffAdjusted = incomingMouthByte 150 - '0'; 151 if(mouthOnOffAdjusted == 1){ 152 Serial.flush(); 153 outgoingMouthByte 154 = 1; 155 Serial.write(outgoingMouthByte); 156 mouthOnOffOld = 1; 157 } 158 159 else if(mouthOnOffAdjusted == 2){ 160 Serial.flush(); 161 outgoingMouthByte 162 = 2; 163 Serial.write(outgoingMouthByte); 164 mouthOnOffOld = 2; 165 } 166 167 } 168} 169//---------------------end serialDoStuff----------------- 170//********************************************************* 171//********************************************************* 172//---------------------begin 173 mouthDoStuff ------------------- 174 175void mouthDoStuff(){ 176 int soundDetected; 177 // stores value from sound pin 178 int soundLevel; // converted values that only 179 include 512-1024 180 int servoMap; // conversion from 0-255 to 100-70 181 soundDetected 182 = analogRead(soundPin); // capture audio signal from dc bias circuit 183 if(soundDetected<=512){ 184 // runs when negative amplitude detected 185 soundLevel = (512-soundDetected+512); 186 // takes numbers below 512 and tacks em on top of 512 to create positive amplitudes 187 188 } 189 else{ 190 soundLevel = soundDetected; // stores positive amplitudes 191 192 } 193 servoMap = map(soundLevel, 570, 610, 100, 50); // sound map 0-255 is mapped 194 to truncated and inverted servo sweep 100-70 195 if(soundLevel < 700){ 196 if(servoMap 197 < 100){ 198 mouthServo.write(servoMap); 199 Serial.print("soundLevel 200 "); 201 Serial.println(soundLevel); 202 Serial.print(" servoMap 203 "); 204 Serial.println(servoMap); 205 Serial.print(" soundDetected 206 "); 207 Serial.println(soundDetected); 208 } 209 } 210 else{ 211 mouthServo.write(95); 212 213 Serial.print("soundLevel "); 214 Serial.println(soundLevel); 215 Serial.print(" 216 servoMap "); 217 Serial.println(servoMap); 218 Serial.print(" 219 soundDetected "); 220 Serial.println(soundDetected); 221 222 } 223 // return soundLevel; 224} 225//// ++++++++++++++++++end mouthDoStuff 226 +++++++++++++++++++++++++++++++++ 227//********************************************************* 228//********************************************************* 229//---------------------begin 230 blink slow------------------- 231void blinkSlow(){ 232unsigned long currentMillis 233 = millis(); 234const long interval1 = 500; 235 236 if(currentMillis - previousMillis 237 >= interval1) { 238 previousMillis = currentMillis; 239 if(ledState == LOW){ 240 241 ledState = HIGH; 242 } 243 else{ 244 ledState = LOW; 245 } 246 247 digitalWrite(ledPin, ledState); 248 } 249} 250//---------------------end blink 251 slow------------------- 252//---------------------begin blink fast ------------------- 253void 254 blinkFast(){ 255unsigned long currentMillis = millis(); 256const long interval2 257 = 75; 258 if(currentMillis - previousMillis >= interval2){ 259 previousMillis 260 = currentMillis; 261 if(ledState == LOW){ 262 ledState = HIGH; 263 } 264 265 else{ 266 ledState = LOW; 267 } 268 digitalWrite(ledPin, ledState); 269 270 } 271} 272//---------------------end blink fast ------------------- 273//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 274//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 275//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 276
22102018 graves uno mouth
c_cpp
uno code to sense sound and move mouth
1/* 2last edit monday oct 22 2018 3 4gravesunomouth 5 6graves 7 project 8arduino Uno 9Slave 1 10coded from scratch by wylie jones 11wyliejones@gmail.com 12 13Graves 14 multi arduino build 10/2018 15Arduino mega 2560 with 240/320 tft and micro sd card 16 (for storing screen backgrounds) 17two arduino uno's 18slave1 arduino uno to sense 19 sound from graves and echo dot to control mouth 20slave2 arduino uno to control 21 passive sensor array and head servo 22 23sound is sensed with a simple DC bias 24 circuit to capture line level input to be used as a digital signal 25 26 analogue 27 pin speaker + 28 \(yellow signal / 29 (red from speaker) 30 \ wire) / 31 \\ 32 / 33 *--------[=]-----------*---------[=]----------* 34 35 | 100k resistor \ 100k resistor | 36 | \\ 37 | 38 |(red with white) \ |to arduino 39 ground (black with white) 40to arduino 5v+ speaker - 41 (black 42 from speaker) 43 44*/ 45#include <Servo.h> 46#include <SPI.h> 47 48//---------------------begin 49 declarations----------------------- 50// for servo actions 51Servo mouthServo; 52 53// 54 for gathering and mapping sound data 55int soundPinGraves=A3; // incoming lead 56 from graves dc bias circuit 57int soundPinEcho=A4; // incoming lead from echo dc 58 bias circuit 59int soundDetectedEcho; // stores value from sound pin 60int soundLevelEcho; 61 // converted values that only include 512-1024 62int soundMapEcho; // conversion 63 from 512-1024 to 0-255 64int servoMapEcho; // conversion from 0-255 to 100-70 65int 66 soundDetectedGraves; // stores value from sound pin 67int soundLevelGraves; // 68 converted values that only include 512-1024 69int soundMapGraves; // conversion 70 from 512-1024 to 0-255 71int servoMapGraves; // conversion from 0-255 to 100-70 72 73// 74 communication 75char incomingMouthByte; // for incoming serial data 76char outgoingMouthByte; // 77 for a bit more talkative serial data 78int mouthOnOffNew; // stores mouth state 79 from serial connection 80int mouthOnOffOld; // stores mouth state from serial connection 81int 82 mouthOnOffAdjusted; // value adjusted by 48 for ascii 83 84// for blinking 85const 86 int ledPin = LED_BUILTIN;// the number of the LED pin 87int ledState = LOW; // 88 ledState used to set the LED 89unsigned long previousMillis = 0; // will 90 store last time LED was updated 91//---------------------end declarations----------------------- 92//********************************************************* 93//********************************************************* 94//---------------------begin 95 void setup----------------------- 96//---------------------begin void setup----------------------- 97//---------------------begin 98 void setup----------------------- 99void setup(){ 100 delay(5000); 101 Serial.begin(9600); 102 103 mouthServo.attach(6); 104 incomingMouthByte = 0; // for incoming serial data 105 106 outgoingMouthByte = 0; // for a little more talkative serial data 107 mouthOnOffNew 108 = 1; // stores mouth state from serial connection 109 mouthOnOffOld = 1; // stores 110 mouth state from serial connection 111 pinMode(ledPin, OUTPUT); 112 pinMode(soundPinEcho, 113 INPUT); 114 pinMode(soundPinGraves, INPUT); 115} 116//---------------------end 117 void setup----------------------- 118//---------------------end void setup----------------------- 119//---------------------end 120 void setup----------------------- 121//********************************************************** 122//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 123//********************************************************** 124//---------------------begin 125 void loop----------------------- 126//---------------------begin void loop----------------------- 127//---------------------begin 128 void loop----------------------- 129void loop(){ 130 serialDoStuff(); 131 if(mouthOnOffNew 132 == mouthOnOffOld){ 133 if(mouthOnOffNew == 1){ 134 blinkFast(); 135 136 mouthDoStuffGraves(); 137 mouthDoStuffEcho(); 138 } 139 if(mouthOnOffNew 140 == 2){ 141 blinkSlow(); 142 } 143 } 144 else if(mouthOnOffNew != 145 mouthOnOffOld){ 146 mouthOnOffNew = mouthOnOffOld; 147 } 148} 149//---------------------end 150 void loop----------------------- 151//---------------------end void loop----------------------- 152//---------------------end 153 void loop----------------------- 154//********************************************************* 155//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 156//********************************************************* 157//---------------------begin 158 serialDoStuff ----------------- 159void serialDoStuff(){ 160 if(Serial.available() 161 > 0){ 162 incomingMouthByte = Serial.read(); 163 mouthOnOffAdjusted = incomingMouthByte 164 - '0'; 165 if(mouthOnOffAdjusted == 1){ 166 Serial.flush(); 167 outgoingMouthByte 168 = 1; 169 Serial.write(outgoingMouthByte); 170 mouthOnOffOld = 1; 171 } 172 173 else if(mouthOnOffAdjusted == 2){ 174 Serial.flush(); 175 outgoingMouthByte 176 = 2; 177 Serial.write(outgoingMouthByte); 178 mouthOnOffOld = 2; 179 } 180/* 181else 182 if(mouthOnOffAdjusted == 3){ 183 Serial.flush(); 184 outgoingMouthByte 185 = 3; 186 Serial.write(outgoingMouthByte); 187 mouthOnOffOld = 3; 188 } 189 190 else if(mouthOnOffAdjusted == 4){ 191 Serial.flush(); 192 outgoingMouthByte 193 = 4; 194 Serial.write(outgoingMouthByte); 195 mouthOnOffOld = 4; 196 } 197 198 199 */ 200 } 201} 202//---------------------end serialDoStuff----------------- 203//********************************************************* 204//********************************************************* 205//---------------------begin 206 mouthDoStuffGraves ------------------- 207 208void mouthDoStuffGraves(){ 209 int 210 soundDetectedGraves; // stores value from sound pin 211 int soundLevelGraves; // 212 converted values that only include 512-1024 213 int servoMapGraves; // conversion 214 from 0-255 to 100-70 215 216 217 soundDetectedGraves = analogRead(soundPinGraves); 218 // capture audio signal from dc bias circuit 219 if(soundDetectedGraves<=512){ 220 // runs when negative amplitude detected 221 soundLevelGraves = (512-soundDetectedGraves+512); 222 // takes numbers below 512 and tacks em on top of 512 to create positive amplitudes 223 224 } 225 else{ 226 soundLevelGraves = soundDetectedGraves; // stores positive 227 amplitudes 228 } 229 230 servoMapGraves = map(soundLevelGraves, 570, 610, 100, 231 50); // sound map 0-255 is mapped to truncated and inverted servo sweep 100-70 232 233 if(soundLevelGraves < 700 ){ 234 if(servoMapGraves < 100){ 235 mouthServo.write(servoMapGraves); 236 237 Serial.print("soundLevelGraves "); 238 Serial.println(soundLevelGraves); 239 240 Serial.print(" servoMapGraves "); 241 Serial.println(servoMapGraves); 242 243 Serial.print(" soundDetectedGraves "); 244 245 Serial.println(soundDetectedGraves); 246 } 247 } 248 else{ 249 mouthServo.write(95); 250 251 Serial.print("soundLevelGraves "); 252 Serial.println(soundLevelGraves); 253 254 Serial.print(" servoMapGraves "); 255 Serial.println(servoMapGraves); 256 257 Serial.print(" soundDetectedGraves "); 258 Serial.println(soundDetectedGraves); 259 260 } 261 // return soundLevelGraves; 262} 263 264//// ++++++++++++++++++end mouthDoStuffGraves 265 +++++++++++++++++++++++++++++++++ 266//********************************************************* 267//********************************************************* 268//---------------------begin 269 mouthDoStuffEcho ------------------- 270 271void mouthDoStuffEcho(){ 272 int soundDetectedEcho; 273 // stores value from sound pin 274 int soundLevelEcho; // converted values that 275 only include 512-1024 276 int servoMapEcho; // conversion from 0-255 to 100-70 277 278 279 280 soundDetectedEcho = analogRead(soundPinEcho); // capture audio signal from dc 281 bias circuit 282 if(soundDetectedEcho<=512){ // runs when negative amplitude detected 283 284 soundLevelEcho = (512-soundDetectedEcho+512); // takes numbers below 512 and 285 tacks em on top of 512 to create positive amplitudes 286 } 287 else{ 288 soundLevelEcho 289 = soundDetectedEcho; // stores positive amplitudes 290 } 291 292 servoMapEcho 293 = map(soundLevelEcho, 570, 610, 100, 50); // sound map 0-255 is mapped to truncated 294 and inverted servo sweep 100-70 295 if(soundLevelEcho < 700 ){ 296 if(servoMapEcho 297 < 100){ 298 mouthServo.write(servoMapEcho); 299 Serial.print("soundLevelEcho 300 "); 301 Serial.println(soundLevelEcho); 302 Serial.print(" servoMapEcho 303 "); 304 Serial.println(servoMapEcho); 305 Serial.print(" soundDetectedEcho 306 "); 307 Serial.println(soundDetectedEcho); 308 } 309 } 310 else{ 311 312 mouthServo.write(95); 313 Serial.print("soundLevelEcho "); 314 Serial.println(soundLevelEcho); 315 316 Serial.print(" servoMapEcho "); 317 Serial.println(servoMapEcho); 318 319 Serial.print(" soundDetectedEcho "); 320 Serial.println(soundDetectedEcho); 321 322 } 323 // return soundLevelEcho; 324} 325 326//// ++++++++++++++++++end mouthDoStuffEcho 327 +++++++++++++++++++++++++++++++++ 328//********************************************************* 329//********************************************************* 330//---------------------begin 331 blink slow------------------- 332void blinkSlow(){ 333unsigned long currentMillis 334 = millis(); 335const long interval1 = 500; 336 337 if(currentMillis - previousMillis 338 >= interval1) { 339 previousMillis = currentMillis; 340 if(ledState == LOW){ 341 342 ledState = HIGH; 343 } 344 else{ 345 ledState = LOW; 346 } 347 348 digitalWrite(ledPin, ledState); 349 } 350} 351//---------------------end blink 352 slow------------------- 353//---------------------begin blink fast ------------------- 354void 355 blinkFast(){ 356unsigned long currentMillis = millis(); 357const long interval2 358 = 75; 359 if(currentMillis - previousMillis >= interval2){ 360 previousMillis 361 = currentMillis; 362 if(ledState == LOW){ 363 ledState = HIGH; 364 } 365 366 else{ 367 ledState = LOW; 368 } 369 digitalWrite(ledPin, ledState); 370 371 } 372} 373//---------------------end blink fast ------------------- 374//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 375//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 376//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 377 378
very rough draft
c_cpp
first brainstorm as to how the code might come together
1/* 2Graves multi arduino build 10/2018 3Arduino mega 2560 with 4 240/320 tft and micro sd card (for storing screen backgrounds) 5two arduino uno's 6slave1 7 arduino uno to sense sound from graves and echo dot to control mouth 8slave2 arduino 9 uno to control passive sensor array and head servo 10 11sound is sensed with a 12 simple DC bias circuit to capture line level input to be used as a digital signal 13 14 15 analogue pin speaker + 16 \\ 17 / (red from speaker) 18 \ / 19 20 \ / 21 *--------[=]-----------*---------[=]----------* 22 23 | resistor \ resistor | 24 | \\ 25 | 26 |(red with white) \ |to arduino 27 ground (black with white) 28to arduino 5v+ speaker - 29 (black 30 from speaker) 31 32*/ 33 34#include <TFTv2.h> 35#include <SPI.h> 36#include 37 <SeeedTouchScreen.h> 38 39//********************************************************* 40//********************************************************* 41 42// 43 begin void setup 44// begin void setup 45// begin void setup 46// begin void 47 setup 48// begin void setup 49// begin void setup 50// begin void setup 51// 52 begin void setup 53// begin void setup 54// begin void setup 55// begin void 56 setup 57 58void setup() { 59 // need timer to track screen timeout 60 // set 61 screen to on and let timer run to turn off 62 63 64} // void setup() 65 66// 67 end void setup 68// end void setup 69// end void setup 70// end void setup 71// 72 end void setup 73// end void setup 74// end void setup 75// end void setup 76 77//********************************************************* 78//********************************************************* 79 80// 81 begin void loop 82// begin void loop 83// begin void loop 84// begin void loop 85// 86 begin void loop 87// begin void loop 88// begin void loop 89// begin void loop 90 91void 92 loop() { 93 // look for interrupt 94 // 95 96} // void loop() 97 98// 99 end of void loop 100// end of void loop 101// end of void loop 102// end of void 103 loop 104// end of void loop 105// end of void loop 106// end of void loop 107// 108 end of void loop 109// end of void loop 110// end of void loop 111// end of void 112 loop 113// end of void loop 114// end of void loop 115// end of void loop 116 117///////////////////////////////////////////////////////////////////////////////////////////////////////// 118////////////////////////////////////////// 119 /////////////////////////////////////////////////// 120///////////////////////////////////////// 121 functions /////////////////////////////////////////////////// 122//////////////////////////////////////// 123 /////////////////////////////////////////////////// 124///////////////////////////////////////////////////////////////////////////////////////////////////////// 125 126//**************************************************************************************************** 127//**************************************************************************************************** 128 129 130 131//**************************************************************************************************** 132//**************************************************************************************************** 133 134//--------------------------begin 135 arduino master data fetch calls---------------------------------- 136// call slave1 137 arduino for data 138// call slave2 arduino for data 139//--------------------------end 140 arduino master data fetch calls------------------------------------ 141 142//**************************************************************************************************** 143//**************************************************************************************************** 144 145//--------------------------begin 146 TFT output code---------------------------------- 147// int displaySensorLogs; 148// 149 displaySensorLogs = tftOutputFunction(); 150//--------------------------end TFT 151 output code------------------------------------ 152 153//**************************************************************************************************** 154//**************************************************************************************************** 155 156//-------------------------- 157 begin slave1 data fetch function -------------------------- 158//-------------------------- 159 end slave1 data fetch function -------------------------- 160 161//**************************************************************************************************** 162//**************************************************************************************************** 163 164//-------------------------- 165 begin slave2 data fetch function -------------------------- 166//-------------------------- 167 end slave2 data fetch function ------------------------- 168 169//**************************************************************************************************** 170//**************************************************************************************************** 171 172 173//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 174//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 175 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 176//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 177 screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 178//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 179 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 180//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 181 182//**************************************************************************************************** 183//**************************************************************************************************** 184 185//--------------------------- 186 Primary screen maps -------------------------------- 187/* 188 189 190 A)master 191 192 a)settings 193 -brightness 194 -contrast 195 -screen lock time 196 out 197 b)sensor monitors 198 -pir 199 *report pir detection 200 201 *report head servo position 202 -sound 203 *sense alexa sound 204 205 *sense graves sound 206 *report mouth servo position 207 *adjust 208 sensitivity? 209 c)bluetooth 210 -on 211 -off 212 -monitor 213 214 215 B)slave1 mouth servo 216 a)test button 217 -open 218 -close 219 -push 220 button chicken switch 221 b)sound sensors on/off 222 -alexa sense 223 224 *on 225 *off 226 *monitor sensor 227 -graves sense 228 229 *on 230 *off 231 *monitor sensors 232 c)sound sensor 233 status 234 -alexa 235 -graves 236 237 C)slave2 head servo 238 a)pir 239 on/off 240 -on 241 -off 242 b)manual point 243 244*/ 245 246 247//**************************************************************************************************** 248//**************************************************************************************************** 249 250 251 252 253 254 255 256//**************************************************************************************************** 257//**************************************************************************************************** 258 259// 260 fin
13102018 - Bodmer to the rescue!
c_cpp
Big shout out to Bodmer for helping identify my spotty understanding of data types. I had wrongly used int to store a millis() value and the prog would crash after a minute or two. changed them to unsigned longs and it chooches along flawlessly now! I was going to rewrite menus, but now I think I'll wait to establish communication from the mega to the dos uno's. I'll figure out what data I can pass back and forth before the menu rewrite. Thanks again, Bodmer!
1/* 2last edit sun oct 13 2018 3coded from scratch by wylie jones 4wyliejones@gmail.com 5 6Graves 7 multi arduino build 10/2018 8Arduino mega 2560 with 240/320 tft and micro sd card 9 (for storing screen backgrounds) 10two arduino uno's 11slave1 arduino uno to sense 12 sound from graves and echo dot to control mouth 13slave2 arduino uno to control 14 passive sensor array and head servo 15 16sound is sensed with a simple DC bias 17 circuit to capture line level input to be used as a digital signal 18 19 analogue 20 pin speaker + 21 \ / 22 (red from speaker) 23 \ / 24 \\ 25 / 26 *--------[=]-----------*---------[=]----------* 27 28 | resistor \ resistor | 29 | \\ 30 | 31 |(red with white) \ |to arduino 32 ground (black with white) 33to arduino 5v+ speaker - 34 (black 35 from speaker) 36 37*/ 38//end notes 39//end notes 40//end notes 41//end notes 42//end 43 notes 44//end notes 45 46 47//********************************************************* 48//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 49//********************************************************* 50 51 52//begin 53 declarations 54//begin declarations 55//begin declarations 56//begin declarations 57//begin 58 declarations 59//begin declarations 60//begin declarations 61 62//#include <TFT.h> 63//#include 64 <Servo.h> 65//#include <stdint.h> 66//#include <SD.h> 67#include <TFTv2.h> 68#include 69 <SPI.h> 70#include <SeeedTouchScreen.h> 71 72//const int PIN_SD_CS = 4; // 73 pin of sd card 74 75TouchScreen ts = TouchScreen(XP, YP, XM, YM); 76int buttonPressed; 77 // stores which button was pressed 78unsigned long newButtonTime; // debounce 79unsigned 80 long oldButtonTime; // debounce 81unsigned long buttonTimeDifference; // debounce 82unsigned 83 long debounceTime; // debounce 84int currentScreen; // identifies current screen 85 by adding x y and z 86int x; // for ones 87int y; // for tens 88int z; // for 89 hundreds 90 91int zMax; // maximum pressure to detect 92int zMin; // minimum 93 pressure to detect 94unsigned long backlightTimer; // for backlight timeout 95int 96 backLightState; // status of backlight 1 for on and 0 for off 97unsigned long 98 backlightTimeDifference; 99unsigned long newBacklightTime; 100unsigned long oldBacklightTime; 101 102//end 103 declarations 104//end declarations 105//end declarations 106//end declarations 107//end 108 declarations 109//end declarations 110//end declarations 111//end declarations 112//end 113 declarations 114 115//********************************************************* 116//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 117//********************************************************* 118 119// 120 begin void setup 121// begin void setup 122// begin void setup 123// begin void 124 setup 125// begin void setup 126// begin void setup 127// begin void setup 128// 129 begin void setup 130// begin void setup 131// begin void setup 132// begin void 133 setup 134void setup() { 135Serial.begin(115200); 136 oldButtonTime = millis(); 137 138 newButtonTime = millis(); 139 Tft.TFTinit(); // init TFT library 140 TFT_BL_ON; 141 // turn on the background light 142 backLightState = 1; 143 x = 0; 144 y 145 = 0; 146 z = 0; 147 buttonPressed = 4; 148 149 //////////////////////////////// 150 151 //// manually set variables //// 152 //////////////////////////////// 153 154 155 debounceTime = 1000; // button debounce in milliseconds 156 zMax 157 = 460; // maximum pressure to detect 158 zMin = 100; // minimum pressure 159 to detect 160 backlightTimer = 5000; // for backlight timeout 161 162 163 164 currentScreen = 0; 165 callScreen(); 166 167} //void setup() 168// end void 169 setup 170// end void setup 171// end void setup 172// end void setup 173// end void 174 setup 175// end void setup 176// end void setup 177// end void setup 178 179//********************************************************* 180//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 181//********************************************************* 182 183// 184 begin void loop 185// begin void loop 186// begin void loop 187// begin void loop 188// 189 begin void loop 190// begin void loop 191// begin void loop 192// begin void loop 193// 194 begin void loop 195// begin void loop 196// begin void loop 197// begin void loop 198// 199 begin void loop 200// begin void loop 201 202void loop() { 203 tftBacklightTimeout(); 204 // check time and turn off backlight 205 tftDetect(); // gather information from 206 touch screen touches 207 buttonTimeDifference = newButtonTime - oldButtonTime; 208 209 if(debounceTime < buttonTimeDifference){ 210 whatScreen(); 211 callScreen(); 212 213 oldButtonTime = newButtonTime; 214 showStuff(); // serial prints 215 tftDisplay(); 216 // display x y coordinates on tft display 217 } 218} //void loop() 219 220// end 221 of void loop 222// end of void loop 223// end of void loop 224// end of void loop 225// 226 end of void loop 227// end of void loop 228// end of void loop 229// end of void 230 loop 231// end of void loop 232// end of void loop 233// end of void loop 234// 235 end of void loop 236// end of void loop 237// end of void loop 238// end of void 239 loop 240 241//**************************************************************************************************** 242//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 243//**************************************************************************************************** 244///////////////////////////////////////////////////////////////////////////////////////////////////////// 245///////////////////////////////////////// 246 functions /////////////////////////////////////////////////// 247///////////////////////////////////////////////////////////////////////////////////////////////////////// 248//**************************************************************************************************** 249//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 250//**************************************************************************************************** 251 252//--------------------------begin 253 tftBacklightTimeout---------------------------------- 254void tftBacklightTimeout(){ 255 256 newBacklightTime = millis(); 257 if(backLightState = 0){ 258 backlightTimeDifference 259 = newBacklightTime - oldBacklightTime; 260 if(backlightTimer > backlightTimeDifference){ 261 262 backlightTimeDifference = newBacklightTime - oldBacklightTime; 263 TFT_BL_ON; 264 // turn on the background light 265 backLightState = 1; 266 oldBacklightTime 267 = millis(); 268 } 269 } 270 if(backLightState = 1){ 271 backlightTimeDifference 272 = newBacklightTime - oldBacklightTime; 273 if(backlightTimer < backlightTimeDifference){ 274 275 backlightTimeDifference = newBacklightTime - oldBacklightTime; 276 TFT_BL_OFF; 277 // turn off the background light 278 backLightState = 0; 279 oldBacklightTime 280 = millis(); 281 } 282 } 283} 284//--------------------------end tftBacklightTimeout---------------------------------- 285 286//**************************************************************************************************** 287//**************************************************************************************************** 288 289//--------------------------begin 290 tftDetect---------------------------------- 291//--------------------------begin 292 tftDetect---------------------------------- 293//--------------------------begin 294 tftDetect---------------------------------- 295//--------------------------begin 296 tftDetect---------------------------------- 297int tftDetect(){ 298 Point p = ts.getPoint(); 299 300 if(zMin<p.z && p.z<zMax){ 301 TFT_BL_ON; // turn on the background light 302 303 backLightState = 1; 304 oldBacklightTime = millis(); 305 newButtonTime 306 = millis(); 307 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 308 p.y = map(p.y, 309 TS_MINY, TS_MAXY, 0, 320); 310//Button 1 311 if(75<p.x && p.x<140){ 312 if(100<p.y 313 && p.y<164){ 314 buttonPressed = 1; 315 } 316//Button 2 317 318 if(164<p.y && p.y<240){ 319 buttonPressed = 2; 320 } 321//Button 322 3 323 if(240<p.y && p.y<310){ 324 buttonPressed = 3; 325 } 326 327 } 328 } 329//Button 4 330 if(10<p.x && p.x<75){ 331 if(100<p.y 332 && p.y<240){ 333 buttonPressed = 4; 334 } 335 } 336//Button 337 5 338 if(250<p.x && p.x<275){ 339 if(0<p.y && p.y<75){ 340 buttonPressed 341 = 5; 342 } 343 } 344}//void tftDetect 345//--------------------------end 346 tftDetect code---------------------------------- 347//--------------------------end 348 tftDetect code---------------------------------- 349//--------------------------end 350 tftDetect code---------------------------------- 351//--------------------------end 352 tftDetect code---------------------------------- 353//--------------------------end 354 tftDetect code---------------------------------- 355//**************************************************************************************************** 356//**************************************************************************************************** 357//-------------------------- 358 begin whatScreen function ------------------------- 359//-------------------------- 360 begin whatScreen function ------------------------- 361//-------------------------- 362 begin whatScreen function ------------------------- 363//-------------------------- 364 begin whatScreen function ------------------------- 365 366int whatScreen(){ 367 368 if(x == 0){ 369 if(buttonPressed == 1){ 370 x = x + 1; 371 Serial.println("x 372 + 1"); 373 } 374 if(buttonPressed == 2){ 375 x = x + 2; 376 Serial.println("x 377 + 2"); 378 } 379 if(buttonPressed == 3){ 380 x = x + 3; 381 Serial.println("x 382 + 3"); 383 } 384 if(buttonPressed == 4){ 385 x = 0; 386 Serial.println("x 387 = 0"); 388 } 389 if(buttonPressed == 5){ 390 x = 0; 391 y 392 = 0; 393 z = 0; 394 Serial.println("xyz all 0"); 395 } 396 397 } 398 else if(x >> 0){ 399 if(y == 0){ 400 if(buttonPressed == 401 1){ 402 y = y + 10; 403 Serial.println("y + 10"); 404 } 405 406 if(buttonPressed == 2){ 407 y = y + 20; 408 Serial.println("y 409 + 20"); 410 } 411 if(buttonPressed == 3){ 412 y = y + 30; 413 414 Serial.println("y + 30"); 415 } 416 if(buttonPressed == 417 4){ 418 x = 0; 419 Serial.println("x = 0"); 420 } 421 422 if(buttonPressed == 5){ 423 x = 0; 424 y = 0; 425 z 426 = 0; 427 Serial.println("xyz all 0"); 428 } 429 } 430 else 431 if (y >> 0){ 432 if(buttonPressed == 1){ 433 z = z + 100; 434 435 Serial.println("z + 100"); 436 } 437 if(buttonPressed 438 == 2){ 439 z = z + 200; 440 Serial.println("z + 200"); 441 442 } 443 if(buttonPressed == 3){ 444 z = z + 300; 445 446 Serial.println("z + 300"); 447 } 448 if(buttonPressed 449 == 4){ 450 if(z == 0){ 451 y = 0; 452 Serial.println("y 453 = 0"); 454 } 455 else if(z >> 0){ 456 z = 0; 457 458 Serial.println("z = 0"); 459 } 460 } 461 if(buttonPressed 462 == 5){ 463 x = 0; 464 y = 0; 465 z = 0; 466 Serial.println("xyz 467 all 0"); 468 } 469 }//y>0 470 }//x>0 471 currentScreen = 472 z+y+x; 473} 474//-------------------------- end whatScreen function ------------------------- 475//-------------------------- 476 end whatScreen function ------------------------- 477//-------------------------- 478 end whatScreen function ------------------------- 479//-------------------------- 480 end whatScreen function ------------------------- 481//-------------------------- 482 end whatScreen function ------------------------- 483 484//**************************************************************************************************** 485//**************************************************************************************************** 486 487//--------------------------begin 488 arduino master data fetch calls---------------------------------- 489// call slave1 490 arduino for data 491// call slave2 arduino for data 492//--------------------------end 493 arduino master data fetch calls------------------------------------ 494 495//**************************************************************************************************** 496//**************************************************************************************************** 497 498//--------------------------begin 499 tftDisplay code---------------------------------- 500void tftDisplay(){ 501 Point 502 p = ts.getPoint(); 503 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 504 p.y = map(p.y, 505 TS_MINY, TS_MAXY, 0, 320); 506 Tft.fillRectangle(0, 160, 60, 30, BLACK); 507 508 Tft.drawNumber((p.x), 0, 160, 3, GREEN); 509 Tft.fillRectangle(180, 160, 510 60, 30, BLACK); 511 Tft.drawNumber((p.y), 180, 160, 3, GREEN); 512 Tft.fillRectangle(80, 513 160, 60, 30, BLACK); 514 Tft.drawNumber((buttonPressed), 80, 160, 3, GREEN); 515}// 516 void tftDisplay 517//--------------------------end tftDisplay code------------------------------------ 518 519//**************************************************************************************************** 520//**************************************************************************************************** 521 522//-------------------------- 523 begin slave1 data fetch function -------------------------- 524//-------------------------- 525 end slave1 data fetch function -------------------------- 526 527//**************************************************************************************************** 528//**************************************************************************************************** 529 530//-------------------------- 531 begin slave2 data fetch function -------------------------- 532//-------------------------- 533 end slave2 data fetch function ------------------------- 534 535//**************************************************************************************************** 536//**************************************************************************************************** 537 538//-------------------------- 539 begin serial display function -------------------------- 540void showStuff(){ 541 542 Serial.println("------/ last update /-------"); 543// Serial.println("------begin 544 display-------"); 545 Serial.print("buttonPressed "); 546 Serial.println(buttonPressed); 547 548 Serial.print("x "); 549 Serial.println(x); 550 Serial.print("y "); 551 552 Serial.println(y); 553 Serial.print("z "); 554 Serial.println(z); 555 Serial.print("currentScreen 556 "); 557 Serial.println(currentScreen); 558// Serial.println("-------end display--------"); 559 560 Serial.println(""); 561 Serial.println(""); 562 Serial.println(""); 563 564 } 565//-------------------------- end serial display function ------------------------- 566 567 568//**************************************************************************************************** 569//**************************************************************************************************** 570 571//--------------------------- 572 Primary screen maps -------------------------------- 573/* 574******** 575updates 576 needed 577******** 5781 ditch the contrast 5792 ditch the brightness 5803 setup 581 screen timeout 582 583 584 585 586screen 0000 A)Home 587 screen 0001 a)settings 588 589 screen 0011 -brightness 590 screen 0011 -contrast 591 screen 0011 -screen 592 lock time out 593 screen 0001 b)sensor monitors 594 screen 0021 -pir 595 screen 596 0121 *report pir detection 597 screen 0021 -sound 598 screen 0221 *sense 599 alexa sound 600 screen 0221 *sense graves sound 601 screen 0221 *report 602 mouth servo position 603 screen 0221 *adjust sensitivity? 604 screen 0021 605 -head potentiometer 606 screen 0021 -bluetooth 607 screen 0001 c)bluetooth 608 609 screen 0031 -on 610 screen 0031 -off 611 screen 0031 -monitor 612screen 613 0000 B)Mouth Control 614 screen 0002 a)test button 615 screen 0012 -open 616 617 screen 0012 -close 618 screen 0012 -push button chicken switch 619 screen 620 0002 b)sound sensors on/off 621 screen 0022 -alexa sense 622 screen 623 0122 *on 624 screen 0122 *off 625 screen 0122 *monitor sensor 626 screen 627 0022 -graves sense 628 screen 0222 *on 629 screen 0222 *off 630 631 screen 0222 *monitor sensors 632 screen 0002 c)sound sensor status 633 634 screen 0032 -alexa 635 screen 0032 -graves 636screen 0000 C)Head Control 637 638 screen 0003 a)pir on/off 639 screen 0013 -on 640 screen 0013 -off 641 642 screen 0013 -sensor 643 screen 0003 b)manual point 644 screen 0023 -slider 645*/ 646//**************************************************************************************************** 647//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 648//**************************************************************************************************** 649//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 650//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 651 screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 652//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 653//**************************************************************************************************** 654//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 655//**************************************************************************************************** 656 657//-------------------------- 658 begin callScreen function ------------------------- 659//-------------------------- 660 begin callScreen function ------------------------- 661//-------------------------- 662 begin callScreen function ------------------------- 663//-------------------------- 664 begin callScreen function ------------------------- 665//-------------------------- 666 begin callScreen function ------------------------- 667//-------------------------- 668 begin callScreen function ------------------------- 669//-------------------------- 670 begin callScreen function ------------------------- 671//-------------------------- 672 begin callScreen function ------------------------- 673//-------------------------- 674 begin callScreen function ------------------------- 675//-------------------------- 676 begin callScreen function ------------------------- 677//-------------------------- 678 begin callScreen function ------------------------- 679 680int callScreen(){ 681 682 Tft.fillRectangle(0, 0, 240, 320, BLACK); 683 684//<><><><><><><><><><><><><><><><><><><><><><><><> 685//<><><><><><><><> 686 begin screen 0000 master <><><><><><><><> 687//<><><><><><><><><><><><><><><><><><><><><><><><> 688if(currentScreen 689 == 0){ 690 // " " 691 Tft.drawString("GRAVES",0,5,4, 692 GREEN); 693 Tft.drawString("INTERFACE",10,50,4,GREEN); 694 Tft.drawString("Home", 695 80,130, 3, GREEN); 696 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 697 698 Tft.drawString("Head Control", 10, 260, 3, GREEN); 699} 700//<><><><><><><><><><><><><><><><><><><><><><><><> 701//<><><><><><><><> 702 end screen 0000 master <><><><><><><><><> 703//<><><><><><><><><><><><><><><><><><><><><><><><> 704 705//<><><><><><><><><><><><><><><><><><><><><><><><> 706//<><><><><><><><> 707 begin screen 0001 <><><><><><><><> 708//<><><><><><><><><><><><><><><><><><><><><><><><> 709 710 if(currentScreen == 1){ 711 // " " 712 Tft.drawString("MEGA 713 2560",00,5,4,BLUE); 714 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 715 Tft.drawString("Settings", 716 10,130, 3, BLUE); 717 Tft.drawString("Sensors", 20, 195, 3, BLUE); 718 Tft.drawString("Bluetooth", 719 00, 260, 3, BLUE); 720 Tft.drawString("<", 0, 160, 3, GREEN); // back button 721} 722//<><><><><><><><><><><><><><><><><><><><><><><><> 723//<><><><><><><><> 724 end screen 0001 <><><><><><><><><> 725//<><><><><><><><><><><><><><><><><><><><><><><><> 726 727//<><><><><><><><><><><><><><><><><><><><><><><><> 728//<><><><><><><><> 729 begin screen 0011 <><><><><><><><> 730//<><><><><><><><><><><><><><><><><><><><><><><><> 731 732 if(currentScreen == 11){ 733 // " " 734 Tft.drawString("MEGA 735 2560",00,5,4,BLUE); 736 Tft.drawString("SETTINGS",10,50,4,YELLOW); 737 Tft.drawString("Brightness", 738 80,130, 3, BLUE); 739 Tft.drawString("Contrast", 05, 195, 3, GREEN); 740 741 Tft.drawString("Timeout", 10, 260, 3, GREEN); 742 Tft.drawString("<", 743 0, 160, 3, GREEN); // back button 744} 745 746//<><><><><><><><><><><><><><><><><><><><><><><><> 747//<><><><><><><><> 748 end screen 0011 <><><><><><><><><> 749//<><><><><><><><><><><><><><><><><><><><><><><><> 750 751//<><><><><><><><><><><><><><><><><><><><><><><><> 752//<><><><><><><><> 753 begin screen 0021 <><><><><><><><> 754//<><><><><><><><><><><><><><><><><><><><><><><><> 755 756 if(currentScreen == 21){ 757 // " " 758 Tft.drawString("MEGA 759 2560",00,5,4,BLUE); 760 Tft.drawString("SENSORS",10,50,4,YELLOW); 761 Tft.drawString("PIR 762 Array", 80,130, 3, BLUE); 763 Tft.drawString("Sound", 05, 195, 3, GREEN); 764 765 Tft.drawString("Head Position", 10, 260, 3, GREEN); 766 Tft.drawString("Bluetooth", 767 10, 260, 3, GREEN); 768 Tft.drawString("<", 0, 160, 3, GREEN); // back button 769} 770//<><><><><><><><><><><><><><><><><><><><><><><><> 771//<><><><><><><><> 772 end screen 0021 <><><><><><><><><> 773//<><><><><><><><><><><><><><><><><><><><><><><><> 774 775//<><><><><><><><><><><><><><><><><><><><><><><><> 776//<><><><><><><><> 777 begin screen 0121 <><><><><><><><> 778//<><><><><><><><><><><><><><><><><><><><><><><><> 779 780 if(currentScreen == 121){ 781 // " " 782 Tft.drawString("PIR",0,5,4,BLUE); 783 784 Tft.drawString("ARRAY",10,50,4,YELLOW); 785 Tft.drawString("PIR sensor 786 #", 80, 60, 3, BLUE); 787 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 788 789 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 790 Tft.drawString("PIR 791 sensor #", 80, 130, 3, BLUE); 792 Tft.drawString("PIR sensor #", 80, 130, 793 3, BLUE); 794 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 795 Tft.drawString("<", 796 0, 160, 3, GREEN); // back button 797} 798//<><><><><><><><><><><><><><><><><><><><><><><><> 799//<><><><><><><><> 800 end screen 0121 <><><><><><><><><> 801//<><><><><><><><><><><><><><><><><><><><><><><><> 802 803//<><><><><><><><><><><><><><><><><><><><><><><><> 804//<><><><><><><><> 805 begin screen 0221 <><><><><><><><> 806//<><><><><><><><><><><><><><><><><><><><><><><><> 807 808 if(currentScreen == 221){ 809 // " " 810 Tft.drawString("SOUND",0,5,4,BLUE); 811 812 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 813 Tft.drawString("Sense 814 Graves", 80,130, 3, BLUE); 815 Tft.drawString("Jaw position", 05, 195, 3, 816 GREEN); 817 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 818 Tft.drawString("<", 819 0, 160, 3, GREEN); // back button 820} 821//<><><><><><><><><><><><><><><><><><><><><><><><> 822//<><><><><><><><> 823 end screen 0221 <><><><><><><><><> 824//<><><><><><><><><><><><><><><><><><><><><><><><> 825 826//<><><><><><><><><><><><><><><><><><><><><><><><> 827//<><><><><><><><> 828 begin screen 0031 <><><><><><><><> 829//<><><><><><><><><><><><><><><><><><><><><><><><> 830 831 if(currentScreen == 31){ 832 // " " 833 Tft.drawString("Bluetooth",0,5,4,BLUE); 834 835 Tft.drawString("Control",10,50,4,YELLOW); 836 Tft.drawString("On", 837 80,130, 3, BLUE); 838 Tft.drawString("Off", 05, 195, 3, GREEN); 839 Tft.drawString("Monitor", 840 10, 260, 3, GREEN); 841 Tft.drawString("<", 0, 160, 3, GREEN); // back button 842} 843//<><><><><><><><><><><><><><><><><><><><><><><><> 844//<><><><><><><><> 845 end screen 0031 <><><><><><><><><> 846//<><><><><><><><><><><><><><><><><><><><><><><><> 847 848//<><><><><><><><><><><><><><><><><><><><><><><><> 849//<><><><><><><><> 850 begin screen 0002 <><><><><><><><> 851//<><><><><><><><><><><><><><><><><><><><><><><><> 852 853 if(currentScreen == 2){ 854 // " " 855 Tft.drawString("Mouth",0,5,4,BLUE); 856 857 Tft.drawString("Control",10,50,4,YELLOW); 858 Tft.drawString("Test 859 Jaw", 80,130, 3, BLUE); 860 Tft.drawString("Sensor on/off", 05, 195, 3, 861 GREEN); 862 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 863 Tft.drawString("<", 864 0, 160, 3, GREEN); // back button 865} 866//<><><><><><><><><><><><><><><><><><><><><><><><> 867//<><><><><><><><> 868 end screen 0002 <><><><><><><><><> 869//<><><><><><><><><><><><><><><><><><><><><><><><> 870 871 872//<><><><><><><><><><><><><><><><><><><><><><><><> 873//<><><><><><><><> 874 begin screen 0012 <><><><><><><><> 875//<><><><><><><><><><><><><><><><><><><><><><><><> 876 877 if(currentScreen == 12){ 878 // " " 879 Tft.drawString("Jaw 880 Test",0,5,4,BLUE); 881 Tft.drawString("Operations",10,50,4,YELLOW); 882 883 Tft.drawString("Open", 80,130, 3, BLUE); 884 Tft.drawString("Close", 885 05, 195, 3, GREEN); 886 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 887 888 Tft.drawString("<", 0, 160, 3, GREEN); // back button 889} 890//<><><><><><><><><><><><><><><><><><><><><><><><> 891//<><><><><><><><> 892 end screen 0012 <><><><><><><><><> 893//<><><><><><><><><><><><><><><><><><><><><><><><> 894 895 896//<><><><><><><><><><><><><><><><><><><><><><><><> 897//<><><><><><><><> 898 begin screen 0022 <><><><><><><><> 899//<><><><><><><><><><><><><><><><><><><><><><><><> 900 901 if(currentScreen == 22){ 902 // " " 903 Tft.drawString("Sound",0,5,4,BLUE); 904 905 Tft.drawString("Sensors",10,50,4,YELLOW); 906 Tft.drawString("Alexa 907 Sense", 80,130, 3, BLUE); 908 Tft.drawString("Graves Sense", 05, 195, 3, 909 GREEN); 910 Tft.drawString("Monitor", 10, 260, 3, GREEN); 911 Tft.drawString("<", 912 0, 160, 3, GREEN); // back button 913} 914//<><><><><><><><><><><><><><><><><><><><><><><><> 915//<><><><><><><><> 916 end screen 0022 <><><><><><><><><> 917//<><><><><><><><><><><><><><><><><><><><><><><><> 918 919 920 921//<><><><><><><><><><><><><><><><><><><><><><><><> 922//<><><><><><><><> 923 begin screen 0122 <><><><><><><><> 924//<><><><><><><><><><><><><><><><><><><><><><><><> 925 926 if(currentScreen == 122){ 927 // " " 928 Tft.drawString("Alexa 929 Sense",0,5,4,BLUE); 930 Tft.drawString("Operations",10,50,4,YELLOW); 931 932 Tft.drawString("On", 80,130, 3, BLUE); 933 Tft.drawString("Off", 934 05, 195, 3, GREEN); 935 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 936 937 Tft.drawString("<", 0, 160, 3, GREEN); // back button 938} 939//<><><><><><><><><><><><><><><><><><><><><><><><> 940//<><><><><><><><> 941 end screen 0122 <><><><><><><><><> 942//<><><><><><><><><><><><><><><><><><><><><><><><> 943 944//<><><><><><><><><><><><><><><><><><><><><><><><> 945//<><><><><><><><> 946 begin screen 0222 <><><><><><><><> 947//<><><><><><><><><><><><><><><><><><><><><><><><> 948 949 if(currentScreen == 222){ 950 // " " 951 Tft.drawString("Graves 952 Sense",0,5,4,BLUE); 953 Tft.drawString("Operations",10,50,4,YELLOW); 954 955 Tft.drawString("On", 80,130, 3, BLUE); 956 Tft.drawString("Off", 957 05, 195, 3, GREEN); 958 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 959 960 Tft.drawString("<", 0, 160, 3, GREEN); // back button 961} 962//<><><><><><><><><><><><><><><><><><><><><><><><> 963//<><><><><><><><> 964 end screen 0222 <><><><><><><><><> 965//<><><><><><><><><><><><><><><><><><><><><><><><> 966 967//<><><><><><><><><><><><><><><><><><><><><><><><> 968//<><><><><><><><> 969 begin screen 0032 <><><><><><><><> 970//<><><><><><><><><><><><><><><><><><><><><><><><> 971 972 if(currentScreen == 32){ 973 // " " 974 Tft.drawString("Sound 975 Sense",0,5,4,BLUE); 976 Tft.drawString("Monitors",10,50,4,YELLOW); 977 Tft.drawString("Alexa", 978 80,130, 3, BLUE); 979 Tft.drawString("Graves", 05, 195, 3, GREEN); 980 Tft.drawString("<", 981 0, 160, 3, GREEN); // back button 982} 983//<><><><><><><><><><><><><><><><><><><><><><><><> 984//<><><><><><><><> 985 end screen 0032 <><><><><><><><><> 986//<><><><><><><><><><><><><><><><><><><><><><><><> 987 988//<><><><><><><><><><><><><><><><><><><><><><><><> 989//<><><><><><><><> 990 begin screen 0003 <><><><><><><><> 991//<><><><><><><><><><><><><><><><><><><><><><><><> 992 993 if(currentScreen == 3){ 994 // " " 995 Tft.drawString("Head 996 Control",0,5,4,BLUE); 997 Tft.drawString("Operations",10,50,4,YELLOW); 998 999 Tft.drawString("PIR Array", 80,130, 3, BLUE); 1000 Tft.drawString("Motor 1001 On/Off", 05, 195, 3, GREEN); 1002 Tft.drawString("Manual Point", 10, 260, 1003 3, GREEN); 1004 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1005} 1006//<><><><><><><><><><><><><><><><><><><><><><><><> 1007//<><><><><><><><> 1008 end screen 0003 <><><><><><><><><> 1009//<><><><><><><><><><><><><><><><><><><><><><><><> 1010 1011//<><><><><><><><><><><><><><><><><><><><><><><><> 1012//<><><><><><><><> 1013 begin screen 0013 <><><><><><><><> 1014//<><><><><><><><><><><><><><><><><><><><><><><><> 1015 1016 if(currentScreen == 13){ 1017 // " " 1018 Tft.drawString("PIR 1019 Control",0,5,4,BLUE); 1020 Tft.drawString("Operations",10,50,4,YELLOW); 1021 1022 Tft.drawString("On", 80,130, 3, BLUE); 1023 Tft.drawString("Off", 1024 05, 195, 3, GREEN); 1025 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 1026 1027 Tft.drawString("<", 0, 160, 3, GREEN); // back button 1028} 1029//<><><><><><><><><><><><><><><><><><><><><><><><> 1030//<><><><><><><><> 1031 end screen 0013 <><><><><><><><><> 1032//<><><><><><><><><><><><><><><><><><><><><><><><> 1033 1034//<><><><><><><><><><><><><><><><><><><><><><><><> 1035//<><><><><><><><> 1036 begin screen 0023 <><><><><><><><> 1037//<><><><><><><><><><><><><><><><><><><><><><><><> 1038 1039 if(currentScreen == 23){ 1040 // " " 1041 Tft.drawString("Head 1042 Control",0,5,4,BLUE); 1043 Tft.drawString("Manual Point",10,50,4,YELLOW); 1044 1045 Tft.drawString("Slider", 80,130, 3, BLUE); 1046 Tft.drawString("<", 1047 0, 160, 3, GREEN); // back button 1048} 1049//<><><><><><><><><><><><><><><><><><><><><><><><> 1050//<><><><><><><><> 1051 end screen 0023 <><><><><><><><><> 1052//<><><><><><><><><><><><><><><><><><><><><><><><> 1053 1054 1055////<><><><><><><><><><><><><><><><><><><><><><><><> 1056////<><><><><><><><> 1057 begin screen lost <><><><><><><><> 1058////<><><><><><><><><><><><><><><><><><><><><><><><> 1059// 1060 else if(currentScreen){ 1061// // " " 1062// 1063 Tft.drawString("Screen not",0,5,3,BLUE); 1064// Tft.drawString("found. 1065 Please",40,50,3,YELLOW); 1066// Tft.drawString("use the back", 80,130, 3, 1067 BLUE); 1068// Tft.drawString("button to", 05, 195, 3, GREEN); 1069// Tft.drawString("return 1070 to fun", 10, 260, 3, GREEN); 1071// Tft.drawString("<", 0, 160, 3, GREEN); 1072 // back button 1073//} 1074////<><><><><><><><><><><><><><><><><><><><><><><><> 1075////<><><><><><><><> 1076 end screen lost <><><><><><><><><> 1077////<><><><><><><><><><><><><><><><><><><><><><><><> 1078 1079}// 1080 callScreen 1081//-------------------------- end callScreen function ------------------------- 1082//-------------------------- 1083 end callScreen function ------------------------- 1084//-------------------------- 1085 end callScreen function ------------------------- 1086//-------------------------- 1087 end callScreen function ------------------------- 1088//-------------------------- 1089 end callScreen function ------------------------- 1090//-------------------------- 1091 end callScreen function ------------------------- 1092//-------------------------- 1093 end callScreen function ------------------------- 1094//-------------------------- 1095 end callScreen function ------------------------- 1096//-------------------------- 1097 end callScreen function ------------------------- 1098//-------------------------- 1099 end callScreen function ------------------------- 1100//-------------------------- 1101 end callScreen function ------------------------- 1102//-------------------------- 1103 end callScreen function ------------------------- 1104//-------------------------- 1105 end callScreen function ------------------------- 1106 1107 1108//**************************************************************************************************** 1109//**************************************************************************************************** 1110 1111 1112 1113 1114 1115 1116 1117//**************************************************************************************************** 1118//**************************************************************************************************** 1119 1120// 1121 fin
12102018 later in the day
c_cpp
updated code again. this time with a back light time out. can't figure out why the screen paging program is failing after a minute or two while the back light timer continues. gonna post the code and ask for help.
1/* 2last edit sun oct 12 2018 later in the day 3coded from scratch by wylie jones 4wyliejones@gmail.com 5 6Graves multi arduino build 10/2018 7Arduino mega 2560 with 240/320 tft and micro sd card (for storing screen backgrounds) 8two arduino uno's 9slave1 arduino uno to sense sound from graves and echo dot to control mouth 10slave2 arduino uno to control passive sensor array and head servo 11 12sound is sensed with a simple DC bias circuit to capture line level input to be used as a digital signal 13 14 analogue pin speaker + 15 \ / (red from speaker) 16 \ / 17 \ / 18 *--------[=]-----------*---------[=]----------* 19 | resistor \ resistor | 20 | \ | 21 |(red with white) \ |to arduino ground (black with white) 22to arduino 5v+ speaker - 23 (black from speaker) 24 25*/ 26//end notes 27//end notes 28//end notes 29//end notes 30//end notes 31//end notes 32 33 34//********************************************************* 35//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 36//********************************************************* 37 38 39//begin declarations 40//begin declarations 41//begin declarations 42//begin declarations 43//begin declarations 44//begin declarations 45//begin declarations 46 47//#include <TFT.h> 48//#include <Servo.h> 49//#include <stdint.h> 50//#include <SD.h> 51#include <TFTv2.h> 52#include <SPI.h> 53#include <SeeedTouchScreen.h> 54 55//const int PIN_SD_CS = 4; // pin of sd card 56 57TouchScreen ts = TouchScreen(XP, YP, XM, YM); 58int buttonPressed; // stores which button was pressed 59int newButtonTime; // debounce 60int oldButtonTime; // debounce 61int buttonTimeDifference; // debounce 62int debounceTime; // debounce 63int currentScreen; // identifies current screen by adding x y and z 64int x; // for ones 65int y; // for tens 66int z; // for hundreds 67 68int zMax; // maximum pressure to detect 69int zMin; // minimum pressure to detect 70int backlightTimer; // for backlight timeout 71int backLightState; // status of backlight 1 for on and 0 for off 72int backlightTimeDifference; 73int newBacklightTime; 74int oldBacklightTime; 75 76//end declarations 77//end declarations 78//end declarations 79//end declarations 80//end declarations 81//end declarations 82//end declarations 83//end declarations 84//end declarations 85 86//********************************************************* 87//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 88//********************************************************* 89 90// begin void setup 91// begin void setup 92// begin void setup 93// begin void setup 94// begin void setup 95// begin void setup 96// begin void setup 97// begin void setup 98// begin void setup 99// begin void setup 100// begin void setup 101void setup() { 102Serial.begin(115200); 103 oldButtonTime = millis(); 104 newButtonTime = millis(); 105 Tft.TFTinit(); // init TFT library 106 TFT_BL_ON; // turn on the background light 107 backLightState = 1; 108 x = 0; 109 y = 0; 110 z = 0; 111 buttonPressed = 4; 112 113 //////////////////////////////// 114 //// manually set variables //// 115 //////////////////////////////// 116 117 debounceTime = 1000; // button debounce in milliseconds 118 zMax = 460; // maximum pressure to detect 119 zMin = 100; // minimum pressure to detect 120 backlightTimer = 5000; // for backlight timeout 121 122 123 currentScreen = 0; 124 callScreen(); 125 126} //void setup() 127// end void setup 128// end void setup 129// end void setup 130// end void setup 131// end void setup 132// end void setup 133// end void setup 134// end void setup 135 136//********************************************************* 137//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 138//********************************************************* 139 140// begin void loop 141// begin void loop 142// begin void loop 143// begin void loop 144// begin void loop 145// begin void loop 146// begin void loop 147// begin void loop 148// begin void loop 149// begin void loop 150// begin void loop 151// begin void loop 152// begin void loop 153// begin void loop 154 155void loop() { 156 tftBacklightTimeout(); // check time and turn off backlight 157 tftDetect(); // gather information from touch screen touches 158 buttonTimeDifference = newButtonTime - oldButtonTime; 159 if(debounceTime < buttonTimeDifference){ 160 whatScreen(); 161 callScreen(); 162 oldButtonTime = newButtonTime; 163 showStuff(); // serial prints 164 tftDisplay(); // display x y coordinates on tft display 165 } 166} //void loop() 167 168// end of void loop 169// end of void loop 170// end of void loop 171// end of void loop 172// end of void loop 173// end of void loop 174// end of void loop 175// end of void loop 176// end of void loop 177// end of void loop 178// end of void loop 179// end of void loop 180// end of void loop 181// end of void loop 182// end of void loop 183 184//**************************************************************************************************** 185//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 186//**************************************************************************************************** 187///////////////////////////////////////////////////////////////////////////////////////////////////////// 188///////////////////////////////////////// functions /////////////////////////////////////////////////// 189///////////////////////////////////////////////////////////////////////////////////////////////////////// 190//**************************************************************************************************** 191//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 192//**************************************************************************************************** 193 194//--------------------------begin tftBacklightTimeout---------------------------------- 195void tftBacklightTimeout(){ 196 newBacklightTime = millis(); 197 if(backLightState = 0){ 198 backlightTimeDifference = newBacklightTime - oldBacklightTime; 199 if(backlightTimer > backlightTimeDifference){ 200 backlightTimeDifference = newBacklightTime - oldBacklightTime; 201 TFT_BL_ON; // turn on the background light 202 backLightState = 1; 203 oldBacklightTime = millis(); 204 } 205 } 206 if(backLightState = 1){ 207 backlightTimeDifference = newBacklightTime - oldBacklightTime; 208 if(backlightTimer < backlightTimeDifference){ 209 backlightTimeDifference = newBacklightTime - oldBacklightTime; 210 TFT_BL_OFF; // turn off the background light 211 backLightState = 0; 212 oldBacklightTime = millis(); 213 } 214 } 215} 216//--------------------------end tftBacklightTimeout---------------------------------- 217 218//**************************************************************************************************** 219//**************************************************************************************************** 220 221//--------------------------begin tftDetect---------------------------------- 222//--------------------------begin tftDetect---------------------------------- 223//--------------------------begin tftDetect---------------------------------- 224//--------------------------begin tftDetect---------------------------------- 225int tftDetect(){ 226 Point p = ts.getPoint(); 227 if(zMin<p.z && p.z<zMax){ 228 TFT_BL_ON; // turn on the background light 229 backLightState = 1; 230 oldBacklightTime = millis(); 231 newButtonTime = millis(); 232 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 233 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 234//Button 1 235 if(75<p.x && p.x<140){ 236 if(100<p.y && p.y<164){ 237 buttonPressed = 1; 238 } 239//Button 2 240 if(164<p.y && p.y<240){ 241 buttonPressed = 2; 242 } 243//Button 3 244 if(240<p.y && p.y<310){ 245 buttonPressed = 3; 246 } 247 } 248 } 249//Button 4 250 if(10<p.x && p.x<75){ 251 if(100<p.y && p.y<240){ 252 buttonPressed = 4; 253 } 254 } 255//Button 5 256 if(250<p.x && p.x<275){ 257 if(0<p.y && p.y<75){ 258 buttonPressed = 5; 259 } 260 } 261}//void tftDetect 262//--------------------------end tftDetect code---------------------------------- 263//--------------------------end tftDetect code---------------------------------- 264//--------------------------end tftDetect code---------------------------------- 265//--------------------------end tftDetect code---------------------------------- 266//--------------------------end tftDetect code---------------------------------- 267//**************************************************************************************************** 268//**************************************************************************************************** 269//-------------------------- begin whatScreen function ------------------------- 270//-------------------------- begin whatScreen function ------------------------- 271//-------------------------- begin whatScreen function ------------------------- 272//-------------------------- begin whatScreen function ------------------------- 273 274int whatScreen(){ 275 if(x == 0){ 276 if(buttonPressed == 1){ 277 x = x + 1; 278 Serial.println("x + 1"); 279 } 280 if(buttonPressed == 2){ 281 x = x + 2; 282 Serial.println("x + 2"); 283 } 284 if(buttonPressed == 3){ 285 x = x + 3; 286 Serial.println("x + 3"); 287 } 288 if(buttonPressed == 4){ 289 x = 0; 290 Serial.println("x = 0"); 291 } 292 if(buttonPressed == 5){ 293 x = 0; 294 y = 0; 295 z = 0; 296 Serial.println("xyz all 0"); 297 } 298 } 299 else if(x >> 0){ 300 if(y == 0){ 301 if(buttonPressed == 1){ 302 y = y + 10; 303 Serial.println("y + 10"); 304 } 305 if(buttonPressed == 2){ 306 y = y + 20; 307 Serial.println("y + 20"); 308 } 309 if(buttonPressed == 3){ 310 y = y + 30; 311 Serial.println("y + 30"); 312 } 313 if(buttonPressed == 4){ 314 x = 0; 315 Serial.println("x = 0"); 316 } 317 if(buttonPressed == 5){ 318 x = 0; 319 y = 0; 320 z = 0; 321 Serial.println("xyz all 0"); 322 } 323 } 324 else if (y >> 0){ 325 if(buttonPressed == 1){ 326 z = z + 100; 327 Serial.println("z + 100"); 328 } 329 if(buttonPressed == 2){ 330 z = z + 200; 331 Serial.println("z + 200"); 332 } 333 if(buttonPressed == 3){ 334 z = z + 300; 335 Serial.println("z + 300"); 336 } 337 if(buttonPressed == 4){ 338 if(z == 0){ 339 y = 0; 340 Serial.println("y = 0"); 341 } 342 else if(z >> 0){ 343 z = 0; 344 Serial.println("z = 0"); 345 } 346 } 347 if(buttonPressed == 5){ 348 x = 0; 349 y = 0; 350 z = 0; 351 Serial.println("xyz all 0"); 352 } 353 }//y>0 354 }//x>0 355 currentScreen = z+y+x; 356} 357//-------------------------- end whatScreen function ------------------------- 358//-------------------------- end whatScreen function ------------------------- 359//-------------------------- end whatScreen function ------------------------- 360//-------------------------- end whatScreen function ------------------------- 361//-------------------------- end whatScreen function ------------------------- 362 363//**************************************************************************************************** 364//**************************************************************************************************** 365 366//--------------------------begin arduino master data fetch calls---------------------------------- 367// call slave1 arduino for data 368// call slave2 arduino for data 369//--------------------------end arduino master data fetch calls------------------------------------ 370 371//**************************************************************************************************** 372//**************************************************************************************************** 373 374//--------------------------begin tftDisplay code---------------------------------- 375void tftDisplay(){ 376 Point p = ts.getPoint(); 377 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); 378 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); 379 Tft.fillRectangle(0, 160, 60, 30, BLACK); 380 Tft.drawNumber((p.x), 0, 160, 3, GREEN); 381 Tft.fillRectangle(180, 160, 60, 30, BLACK); 382 Tft.drawNumber((p.y), 180, 160, 3, GREEN); 383 Tft.fillRectangle(80, 160, 60, 30, BLACK); 384 Tft.drawNumber((buttonPressed), 80, 160, 3, GREEN); 385}// void tftDisplay 386//--------------------------end tftDisplay code------------------------------------ 387 388//**************************************************************************************************** 389//**************************************************************************************************** 390 391//-------------------------- begin slave1 data fetch function -------------------------- 392//-------------------------- end slave1 data fetch function -------------------------- 393 394//**************************************************************************************************** 395//**************************************************************************************************** 396 397//-------------------------- begin slave2 data fetch function -------------------------- 398//-------------------------- end slave2 data fetch function ------------------------- 399 400//**************************************************************************************************** 401//**************************************************************************************************** 402 403//-------------------------- begin serial display function -------------------------- 404void showStuff(){ 405 Serial.println("------/ last update /-------"); 406// Serial.println("------begin display-------"); 407 Serial.print("buttonPressed "); 408 Serial.println(buttonPressed); 409 Serial.print("x "); 410 Serial.println(x); 411 Serial.print("y "); 412 Serial.println(y); 413 Serial.print("z "); 414 Serial.println(z); 415 Serial.print("currentScreen "); 416 Serial.println(currentScreen); 417// Serial.println("-------end display--------"); 418 Serial.println(""); 419 Serial.println(""); 420 Serial.println(""); 421 } 422//-------------------------- end serial display function ------------------------- 423 424 425//**************************************************************************************************** 426//**************************************************************************************************** 427 428//--------------------------- Primary screen maps -------------------------------- 429/* 430******** 431updates needed 432******** 4331 ditch the contrast 4342 ditch the brightness 4353 setup screen timeout 436 437 438 439 440screen 0000 A)Home 441 screen 0001 a)settings 442 screen 0011 -brightness 443 screen 0011 -contrast 444 screen 0011 -screen lock time out 445 screen 0001 b)sensor monitors 446 screen 0021 -pir 447 screen 0121 *report pir detection 448 screen 0021 -sound 449 screen 0221 *sense alexa sound 450 screen 0221 *sense graves sound 451 screen 0221 *report mouth servo position 452 screen 0221 *adjust sensitivity? 453 screen 0021 -head potentiometer 454 screen 0021 -bluetooth 455 screen 0001 c)bluetooth 456 screen 0031 -on 457 screen 0031 -off 458 screen 0031 -monitor 459screen 0000 B)Mouth Control 460 screen 0002 a)test button 461 screen 0012 -open 462 screen 0012 -close 463 screen 0012 -push button chicken switch 464 screen 0002 b)sound sensors on/off 465 screen 0022 -alexa sense 466 screen 0122 *on 467 screen 0122 *off 468 screen 0122 *monitor sensor 469 screen 0022 -graves sense 470 screen 0222 *on 471 screen 0222 *off 472 screen 0222 *monitor sensors 473 screen 0002 c)sound sensor status 474 screen 0032 -alexa 475 screen 0032 -graves 476screen 0000 C)Head Control 477 screen 0003 a)pir on/off 478 screen 0013 -on 479 screen 0013 -off 480 screen 0013 -sensor 481 screen 0003 b)manual point 482 screen 0023 -slider 483*/ 484//**************************************************************************************************** 485//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 486//**************************************************************************************************** 487//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 488//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ screens \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 489//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 490//**************************************************************************************************** 491//<*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*><*> 492//**************************************************************************************************** 493 494//-------------------------- begin callScreen function ------------------------- 495//-------------------------- begin callScreen function ------------------------- 496//-------------------------- begin callScreen function ------------------------- 497//-------------------------- begin callScreen function ------------------------- 498//-------------------------- begin callScreen function ------------------------- 499//-------------------------- begin callScreen function ------------------------- 500//-------------------------- begin callScreen function ------------------------- 501//-------------------------- begin callScreen function ------------------------- 502//-------------------------- begin callScreen function ------------------------- 503//-------------------------- begin callScreen function ------------------------- 504//-------------------------- begin callScreen function ------------------------- 505 506int callScreen(){ 507 Tft.fillRectangle(0, 0, 240, 320, BLACK); 508 509//<><><><><><><><><><><><><><><><><><><><><><><><> 510//<><><><><><><><> begin screen 0000 master <><><><><><><><> 511//<><><><><><><><><><><><><><><><><><><><><><><><> 512if(currentScreen == 0){ 513 // " " 514 Tft.drawString("GRAVES",0,5,4, GREEN); 515 Tft.drawString("INTERFACE",10,50,4,GREEN); 516 Tft.drawString("Home", 80,130, 3, GREEN); 517 Tft.drawString("Mouth Control", 05, 195, 3, GREEN); 518 Tft.drawString("Head Control", 10, 260, 3, GREEN); 519} 520//<><><><><><><><><><><><><><><><><><><><><><><><> 521//<><><><><><><><> end screen 0000 master <><><><><><><><><> 522//<><><><><><><><><><><><><><><><><><><><><><><><> 523 524//<><><><><><><><><><><><><><><><><><><><><><><><> 525//<><><><><><><><> begin screen 0001 <><><><><><><><> 526//<><><><><><><><><><><><><><><><><><><><><><><><> 527 if(currentScreen == 1){ 528 // " " 529 Tft.drawString("MEGA 2560",00,5,4,BLUE); 530 Tft.drawString("FUNCTIONS",00,50,4,BLUE); 531 Tft.drawString("Settings", 10,130, 3, BLUE); 532 Tft.drawString("Sensors", 20, 195, 3, BLUE); 533 Tft.drawString("Bluetooth", 00, 260, 3, BLUE); 534 Tft.drawString("<", 0, 160, 3, GREEN); // back button 535} 536//<><><><><><><><><><><><><><><><><><><><><><><><> 537//<><><><><><><><> end screen 0001 <><><><><><><><><> 538//<><><><><><><><><><><><><><><><><><><><><><><><> 539 540//<><><><><><><><><><><><><><><><><><><><><><><><> 541//<><><><><><><><> begin screen 0011 <><><><><><><><> 542//<><><><><><><><><><><><><><><><><><><><><><><><> 543 if(currentScreen == 11){ 544 // " " 545 Tft.drawString("MEGA 2560",00,5,4,BLUE); 546 Tft.drawString("SETTINGS",10,50,4,YELLOW); 547 Tft.drawString("Brightness", 80,130, 3, BLUE); 548 Tft.drawString("Contrast", 05, 195, 3, GREEN); 549 Tft.drawString("Timeout", 10, 260, 3, GREEN); 550 Tft.drawString("<", 0, 160, 3, GREEN); // back button 551} 552 553//<><><><><><><><><><><><><><><><><><><><><><><><> 554//<><><><><><><><> end screen 0011 <><><><><><><><><> 555//<><><><><><><><><><><><><><><><><><><><><><><><> 556 557//<><><><><><><><><><><><><><><><><><><><><><><><> 558//<><><><><><><><> begin screen 0021 <><><><><><><><> 559//<><><><><><><><><><><><><><><><><><><><><><><><> 560 if(currentScreen == 21){ 561 // " " 562 Tft.drawString("MEGA 2560",00,5,4,BLUE); 563 Tft.drawString("SENSORS",10,50,4,YELLOW); 564 Tft.drawString("PIR Array", 80,130, 3, BLUE); 565 Tft.drawString("Sound", 05, 195, 3, GREEN); 566 Tft.drawString("Head Position", 10, 260, 3, GREEN); 567 Tft.drawString("Bluetooth", 10, 260, 3, GREEN); 568 Tft.drawString("<", 0, 160, 3, GREEN); // back button 569} 570//<><><><><><><><><><><><><><><><><><><><><><><><> 571//<><><><><><><><> end screen 0021 <><><><><><><><><> 572//<><><><><><><><><><><><><><><><><><><><><><><><> 573 574//<><><><><><><><><><><><><><><><><><><><><><><><> 575//<><><><><><><><> begin screen 0121 <><><><><><><><> 576//<><><><><><><><><><><><><><><><><><><><><><><><> 577 if(currentScreen == 121){ 578 // " " 579 Tft.drawString("PIR",0,5,4,BLUE); 580 Tft.drawString("ARRAY",10,50,4,YELLOW); 581 Tft.drawString("PIR sensor #", 80, 60, 3, BLUE); 582 Tft.drawString("PIR sensor #", 80, 85, 3, BLUE); 583 Tft.drawString("PIR sensor #", 80, 105, 3, BLUE); 584 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 585 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 586 Tft.drawString("PIR sensor #", 80, 130, 3, BLUE); 587 Tft.drawString("<", 0, 160, 3, GREEN); // back button 588} 589//<><><><><><><><><><><><><><><><><><><><><><><><> 590//<><><><><><><><> end screen 0121 <><><><><><><><><> 591//<><><><><><><><><><><><><><><><><><><><><><><><> 592 593//<><><><><><><><><><><><><><><><><><><><><><><><> 594//<><><><><><><><> begin screen 0221 <><><><><><><><> 595//<><><><><><><><><><><><><><><><><><><><><><><><> 596 if(currentScreen == 221){ 597 // " " 598 Tft.drawString("SOUND",0,5,4,BLUE); 599 Tft.drawString("Sense Alexa",10,50,4,YELLOW); 600 Tft.drawString("Sense Graves", 80,130, 3, BLUE); 601 Tft.drawString("Jaw position", 05, 195, 3, GREEN); 602 Tft.drawString("Jaw Settings", 10, 260, 3, GREEN); 603 Tft.drawString("<", 0, 160, 3, GREEN); // back button 604} 605//<><><><><><><><><><><><><><><><><><><><><><><><> 606//<><><><><><><><> end screen 0221 <><><><><><><><><> 607//<><><><><><><><><><><><><><><><><><><><><><><><> 608 609//<><><><><><><><><><><><><><><><><><><><><><><><> 610//<><><><><><><><> begin screen 0031 <><><><><><><><> 611//<><><><><><><><><><><><><><><><><><><><><><><><> 612 if(currentScreen == 31){ 613 // " " 614 Tft.drawString("Bluetooth",0,5,4,BLUE); 615 Tft.drawString("Control",10,50,4,YELLOW); 616 Tft.drawString("On", 80,130, 3, BLUE); 617 Tft.drawString("Off", 05, 195, 3, GREEN); 618 Tft.drawString("Monitor", 10, 260, 3, GREEN); 619 Tft.drawString("<", 0, 160, 3, GREEN); // back button 620} 621//<><><><><><><><><><><><><><><><><><><><><><><><> 622//<><><><><><><><> end screen 0031 <><><><><><><><><> 623//<><><><><><><><><><><><><><><><><><><><><><><><> 624 625//<><><><><><><><><><><><><><><><><><><><><><><><> 626//<><><><><><><><> begin screen 0002 <><><><><><><><> 627//<><><><><><><><><><><><><><><><><><><><><><><><> 628 if(currentScreen == 2){ 629 // " " 630 Tft.drawString("Mouth",0,5,4,BLUE); 631 Tft.drawString("Control",10,50,4,YELLOW); 632 Tft.drawString("Test Jaw", 80,130, 3, BLUE); 633 Tft.drawString("Sensor on/off", 05, 195, 3, GREEN); 634 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 635 Tft.drawString("<", 0, 160, 3, GREEN); // back button 636} 637//<><><><><><><><><><><><><><><><><><><><><><><><> 638//<><><><><><><><> end screen 0002 <><><><><><><><><> 639//<><><><><><><><><><><><><><><><><><><><><><><><> 640 641 642//<><><><><><><><><><><><><><><><><><><><><><><><> 643//<><><><><><><><> begin screen 0012 <><><><><><><><> 644//<><><><><><><><><><><><><><><><><><><><><><><><> 645 if(currentScreen == 12){ 646 // " " 647 Tft.drawString("Jaw Test",0,5,4,BLUE); 648 Tft.drawString("Operations",10,50,4,YELLOW); 649 Tft.drawString("Open", 80,130, 3, BLUE); 650 Tft.drawString("Close", 05, 195, 3, GREEN); 651 Tft.drawString("Chickn Switch", 10, 260, 3, GREEN); 652 Tft.drawString("<", 0, 160, 3, GREEN); // back button 653} 654//<><><><><><><><><><><><><><><><><><><><><><><><> 655//<><><><><><><><> end screen 0012 <><><><><><><><><> 656//<><><><><><><><><><><><><><><><><><><><><><><><> 657 658 659//<><><><><><><><><><><><><><><><><><><><><><><><> 660//<><><><><><><><> begin screen 0022 <><><><><><><><> 661//<><><><><><><><><><><><><><><><><><><><><><><><> 662 if(currentScreen == 22){ 663 // " " 664 Tft.drawString("Sound",0,5,4,BLUE); 665 Tft.drawString("Sensors",10,50,4,YELLOW); 666 Tft.drawString("Alexa Sense", 80,130, 3, BLUE); 667 Tft.drawString("Graves Sense", 05, 195, 3, GREEN); 668 Tft.drawString("Monitor", 10, 260, 3, GREEN); 669 Tft.drawString("<", 0, 160, 3, GREEN); // back button 670} 671//<><><><><><><><><><><><><><><><><><><><><><><><> 672//<><><><><><><><> end screen 0022 <><><><><><><><><> 673//<><><><><><><><><><><><><><><><><><><><><><><><> 674 675 676 677//<><><><><><><><><><><><><><><><><><><><><><><><> 678//<><><><><><><><> begin screen 0122 <><><><><><><><> 679//<><><><><><><><><><><><><><><><><><><><><><><><> 680 if(currentScreen == 122){ 681 // " " 682 Tft.drawString("Alexa Sense",0,5,4,BLUE); 683 Tft.drawString("Operations",10,50,4,YELLOW); 684 Tft.drawString("On", 80,130, 3, BLUE); 685 Tft.drawString("Off", 05, 195, 3, GREEN); 686 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 687 Tft.drawString("<", 0, 160, 3, GREEN); // back button 688} 689//<><><><><><><><><><><><><><><><><><><><><><><><> 690//<><><><><><><><> end screen 0122 <><><><><><><><><> 691//<><><><><><><><><><><><><><><><><><><><><><><><> 692 693//<><><><><><><><><><><><><><><><><><><><><><><><> 694//<><><><><><><><> begin screen 0222 <><><><><><><><> 695//<><><><><><><><><><><><><><><><><><><><><><><><> 696 if(currentScreen == 222){ 697 // " " 698 Tft.drawString("Graves Sense",0,5,4,BLUE); 699 Tft.drawString("Operations",10,50,4,YELLOW); 700 Tft.drawString("On", 80,130, 3, BLUE); 701 Tft.drawString("Off", 05, 195, 3, GREEN); 702 Tft.drawString("Monitor Sense", 10, 260, 3, GREEN); 703 Tft.drawString("<", 0, 160, 3, GREEN); // back button 704} 705//<><><><><><><><><><><><><><><><><><><><><><><><> 706//<><><><><><><><> end screen 0222 <><><><><><><><><> 707//<><><><><><><><><><><><><><><><><><><><><><><><> 708 709//<><><><><><><><><><><><><><><><><><><><><><><><> 710//<><><><><><><><> begin screen 0032 <><><><><><><><> 711//<><><><><><><><><><><><><><><><><><><><><><><><> 712 if(currentScreen == 32){ 713 // " " 714 Tft.drawString("Sound Sense",0,5,4,BLUE); 715 Tft.drawString("Monitors",10,50,4,YELLOW); 716 Tft.drawString("Alexa", 80,130, 3, BLUE); 717 Tft.drawString("Graves", 05, 195, 3, GREEN); 718 Tft.drawString("<", 0, 160, 3, GREEN); // back button 719} 720//<><><><><><><><><><><><><><><><><><><><><><><><> 721//<><><><><><><><> end screen 0032 <><><><><><><><><> 722//<><><><><><><><><><><><><><><><><><><><><><><><> 723 724//<><><><><><><><><><><><><><><><><><><><><><><><> 725//<><><><><><><><> begin screen 0003 <><><><><><><><> 726//<><><><><><><><><><><><><><><><><><><><><><><><> 727 if(currentScreen == 3){ 728 // " " 729 Tft.drawString("Head Control",0,5,4,BLUE); 730 Tft.drawString("Operations",10,50,4,YELLOW); 731 Tft.drawString("PIR Array", 80,130, 3, BLUE); 732 Tft.drawString("Motor On/Off", 05, 195, 3, GREEN); 733 Tft.drawString("Manual Point", 10, 260, 3, GREEN); 734 Tft.drawString("<", 0, 160, 3, GREEN); // back button 735} 736//<><><><><><><><><><><><><><><><><><><><><><><><> 737//<><><><><><><><> end screen 0003 <><><><><><><><><> 738//<><><><><><><><><><><><><><><><><><><><><><><><> 739 740//<><><><><><><><><><><><><><><><><><><><><><><><> 741//<><><><><><><><> begin screen 0013 <><><><><><><><> 742//<><><><><><><><><><><><><><><><><><><><><><><><> 743 if(currentScreen == 13){ 744 // " " 745 Tft.drawString("PIR Control",0,5,4,BLUE); 746 Tft.drawString("Operations",10,50,4,YELLOW); 747 Tft.drawString("On", 80,130, 3, BLUE); 748 Tft.drawString("Off", 05, 195, 3, GREEN); 749 Tft.drawString("Current Sense", 10, 260, 3, GREEN); 750 Tft.drawString("<", 0, 160, 3, GREEN); // back button 751} 752//<><><><><><><><><><><><><><><><><><><><><><><><> 753//<><><><><><><><> end screen 0013 <><><><><><><><><> 754//<><><><><><><><><><><><><><><><><><><><><><><><> 755 756//<><><><><><><><><><><><><><><><><><><><><><><><> 757//<><><><><><><><> begin screen 0023 <><><><><><><><> 758//<><><><><><><><><><><><><><><><><><><><><><><><> 759 if(currentScreen == 23){ 760 // " " 761 Tft.drawString("Head Control",0,5,4,BLUE); 762 Tft.drawString("Manual Point",10,50,4,YELLOW); 763 Tft.drawString("Slider", 80,130, 3, BLUE); 764 Tft.drawString("<", 0, 160, 3, GREEN); // back button 765} 766//<><><><><><><><><><><><><><><><><><><><><><><><> 767//<><><><><><><><> end screen 0023 <><><><><><><><><> 768//<><><><><><><><><><><><><><><><><><><><><><><><> 769 770 771////<><><><><><><><><><><><><><><><><><><><><><><><> 772////<><><><><><><><> begin screen lost <><><><><><><><> 773////<><><><><><><><><><><><><><><><><><><><><><><><> 774// else if(currentScreen){ 775// // " " 776// Tft.drawString("Screen not",0,5,3,BLUE); 777// Tft.drawString("found. Please",40,50,3,YELLOW); 778// Tft.drawString("use the back", 80,130, 3, BLUE); 779// Tft.drawString("button to", 05, 195, 3, GREEN); 780// Tft.drawString("return to fun", 10, 260, 3, GREEN); 781// Tft.drawString("<", 0, 160, 3, GREEN); // back button 782//} 783////<><><><><><><><><><><><><><><><><><><><><><><><> 784////<><><><><><><><> end screen lost <><><><><><><><><> 785////<><><><><><><><><><><><><><><><><><><><><><><><> 786 787}// callScreen 788//-------------------------- end callScreen function ------------------------- 789//-------------------------- end callScreen function ------------------------- 790//-------------------------- end callScreen function ------------------------- 791//-------------------------- end callScreen function ------------------------- 792//-------------------------- end callScreen function ------------------------- 793//-------------------------- end callScreen function ------------------------- 794//-------------------------- end callScreen function ------------------------- 795//-------------------------- end callScreen function ------------------------- 796//-------------------------- end callScreen function ------------------------- 797//-------------------------- end callScreen function ------------------------- 798//-------------------------- end callScreen function ------------------------- 799//-------------------------- end callScreen function ------------------------- 800//-------------------------- end callScreen function ------------------------- 801 802 803//**************************************************************************************************** 804//**************************************************************************************************** 805 806 807 808 809 810 811 812//**************************************************************************************************** 813//**************************************************************************************************** 814 815// fin
Downloadable files
line level dc bias circuit
sound/speaker wires carry an alternating current from negative 5 volts to positive 5 volts. It's the negative voltage that would damage an arduino input. This circuit sends one speaker wire to ground and the other speaker wire goes in between two resistors on a steady 5 volt supply. The signal wire goes in between the resistors as well. The resistors I used were 10k Ohm. I tried 100k Ohm and immediately had signal issues. The 10uF 16v capacitor acts as a bit of a filter for the sound signal by sitting on the negative speaker wire.
line level dc bias circuit

Comments
Only logged in users can leave comments