SHOW:
|
|
- or go back to the newest paste.
| 1 | // ======================================================================================= | |
| 2 | - | // /////////////////////////Padawan Body Code v1.9X ////////////////////////////////////// |
| 2 | + | // /////////////////////////Padawan Body Code //////////////////////////////////////////// |
| 3 | // ======================================================================================= | |
| 4 | // danf | |
| 5 | - | // Revised Date: 10/21/13 (unofficial revision by PaulM) |
| 5 | + | // Revised Date: 01/01/14 (unofficial revision by PaulM) |
| 6 | // Designed to be used with a second Arduino running the Padawan Dome code | |
| 7 | // EasyTransfer and PS2X_lib libraries by Bill Porter | |
| 8 | // | |
| 9 | // PaulM's tweaks need latest Sabertooth and MP3Trigger libraries from: | |
| 10 | // - https://www.dimensionengineering.com/info/arduino | |
| 11 | // - https://github.com/sansumbrella/MP3Trigger-for-Arduino | |
| 12 | - | // For SyRen Packetized Serial Set Switches 1 and 2 Down, All Others Up |
| 12 | + | |
| 13 | // Set Sabertooth 2x25 Dip Switches 1 and 2 Down, All Others Up | |
| 14 | // For SyRen packetized Serial Set Switches 1 and 2 Down, All Others Up | |
| 15 | // For SyRen Simple Serial Set Switchs 2 & 4 Down, All Others Up | |
| 16 | // Placed a 10K ohm resistor between S1 & GND on the SyRen 10 itself | |
| 17 | // | |
| 18 | // (if using Lithium batteries set switch 3 Down on SyRen & Sabertooth 2x25) | |
| 19 | // | |
| 20 | // Arduino Pins: BotBoarduino Pins: | |
| 21 | // D01 = MP3 Trigger RX* D01 = MP3 Trigger RX* | |
| 22 | // D05 = Syren10 S1** D06 = PS2 DAT | |
| 23 | // D06 = Sabertooth S2*** D07 = PS2 COM | |
| 24 | // D07 = Sabertooth S1 D08 = PS2 ATT | |
| 25 | // D08 = Dome RXI D09 = PS2 CLK | |
| 26 | // D10 = PS2 ATT D10 = Dome RXI | |
| 27 | // D11 = PS2 COM D11 = Syren10 S1** | |
| 28 | // D12 = PS2 DAT D12 = Sabertooth S2*** | |
| 29 | // D13 = PS2 CLK D13 = Sabertooth S1 | |
| 30 | // A4 = LCD DAT A4 = LCD DAT | |
| 31 | // A5 = LCD CLK A5 = LCD CLK | |
| 32 | // D05 = used by internal speaker | |
| 33 | // *If using MP3 Trigger in mode 1, connect MP3 Trigger RX to D03 instead | |
| 34 | // **If using SyRen in mode 3, connect Syren S1 to D01 instead | |
| 35 | // ***S2 is not needed for Sabertooth's serial mode | |
| 36 | // | |
| 37 | - | byte drivespeed = 75; // 0-stop, 127-full speed. |
| 37 | + | // Extra sounds triggered by R2 + Square=54 Circle=55 X=56 Triangle=57 |
| 38 | - | // Recommend beginner: 50 to 75, experienced: 100 to 127, I like 100 |
| 38 | + | |
| 39 | // This program is free software: you can redistribute it and/or modify it . | |
| 40 | - | byte turnspeed = 45; // the higher this number the faster it will spin in place, lower - easier to controll. |
| 40 | + | // This program is distributed in the hope that it will be useful, |
| 41 | - | // Recommend beginner: 40 to 50, experienced: 50 $ up, I like 75 |
| 41 | + | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 42 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 43 | - | byte ramping = 5; // Ramping- the lower this number the longer R2 will take to speedup or slow down, |
| 43 | + | |
| 44 | - | // change this by incriments of 1 |
| 44 | + | |
| 45 | ||
| 46 | - | #define MP3TRIGGERMODE 1 // 0 for regular mode (MP3 Tirgger RX connects to Pin 1) |
| 46 | + | #define drivespeed1 75 //set these 3 to whatever speeds work for you. 0=stop, 127=full speed. |
| 47 | - | // 1 for Software Serial mode (MP3 Trigger connects to Pin 3) |
| 47 | + | #define drivespeed2 100 //Recommend beginner: 50 to 75, experienced: 100 to 127, I like 100. |
| 48 | #define drivespeed3 127 //Set to 0 if you only want 2 speeds. | |
| 49 | ||
| 50 | - | // Do not use Simple Serial mode in close contact with people. |
| 50 | + | #define turnspeed 50 // the higher this number the faster it will spin in place, lower - easier to controll. |
| 51 | - | // NOTE : you can't use MP3TRIGGERMODE 0 with SYRENMODE 3, since they both use Arduino Pin 1 |
| 51 | + | // Recommend beginner: 40 to 50, experienced: 50 $ up, I like 75 |
| 52 | ||
| 53 | - | int domeBaudeRate = 9600; // Set the Serial baude rate for the Syren motor controller |
| 53 | + | #define domespeed 110 // If using a speed controller for the dome, sets the top speed |
| 54 | - | // for packetized options are: 2400, 9600 (default), 19200 or 38400 |
| 54 | + | // Use a number up to 127 for serial |
| 55 | - | // for simple use 9600 . |
| 55 | + | |
| 56 | #define ramping 5 // Ramping- the lower this number the longer R2 will take to speedup or slow down, | |
| 57 | - | byte domecompensation = 2; // For controllers that centering problems, causing slight dome drift in one direction |
| 57 | + | // change this by incriments of 1 |
| 58 | - | // use the lowest number with no drift |
| 58 | + | |
| 59 | #define MP3TRIGMODE 1 // 0 for regular mode (MP3 Tirgger RX connects to Pin 1) | |
| 60 | - | byte domespeed = 110; // If using a speed controller for the dome, sets the top speed |
| 60 | + | // 1 for Software Serial mode (MP3 Trigger connects to Pin 3) |
| 61 | - | // Use a number up to 127 |
| 61 | + | |
| 62 | #define SYRENMODE 3 // 1=Simple Serial , 2=Packetized Software Serial (recommended), 3=Packetized Hardware Serial (S1 connects to Pin 1) | |
| 63 | - | #define VOLJUMP 2 // Speed at which volume is adjusted (1=slowest 5=fastest) |
| 63 | + | // Do not use Simple Serial mode in close contact with people. |
| 64 | // NOTE : you can't use MP3TRIGMODE 0 with SYRENMODE 3, since they both use Arduino Pin 1 | |
| 65 | ||
| 66 | - | #define LCD 0 // Connect to LCD via i2c (pins A4 & A5), default address #0 (A0-A2 not jumpered) |
| 66 | + | #define domecompensation 0 // For controllers that centering problems, causing slight dome drift in one direction |
| 67 | - | // Backlight can be toggled on/off using R1 + Pad Left |
| 67 | + | |
| 68 | - | // (comment out if no LCD is connected) |
| 68 | + | #define drivecompensation 0 // use the lowest number with no drift |
| 69 | // (this sets the Sabertooth's Deadband and will persist between restarts) | |
| 70 | - | #define AUTOMIN 5 // Minimum seconds between sounds in auto mode |
| 70 | + | // Motor powers in the range [-deadband, deadband] will be considered in the deadband, |
| 71 | - | #define AUTOMAX 20 // Maximum seconds between sounds in auto mode |
| 71 | + | // and will not prevent the driver from entering nor cause the driver to leave an idle brake state. |
| 72 | // 0 resets to the default, which is 3. valid setting is 0 to 127. | |
| 73 | - | #define BOARDTYPE 1 // 0 for regular Arduino, 1 for BotBoarduino (uses different PS2, ST & dome pins) |
| 73 | + | |
| 74 | #define domeBaudeRate 9600 // Set the baude rate for the Syren motor controller | |
| 75 | // for packetized options are: 2400, 9600, 19200 and 38400 | |
| 76 | // for simple use 9600 | |
| 77 | ||
| 78 | - | Sabertooth SyR(128); |
| 78 | + | #define VOLJUMP 2 // Speed at which volume is adjusted (1=slowest 5=fast) |
| 79 | #define VOLLIMIT 100 // Quietest volume can be set to (0-255, higher=quieter, over 64 is pretty quiet) | |
| 80 | ||
| 81 | #define LCD 0 // Connect to LCD via i2c (pins A4 & A5), default address #0 (A0-A2 not jumpered) | |
| 82 | // Backlight can be toggled on/off using R1 + Pad Left | |
| 83 | // (comment out if no LCD is connected) | |
| 84 | ||
| 85 | //Dome Automation Settings... | |
| 86 | #define AUTOMIN 5 // Minimum seconds between sounds in auto mode | |
| 87 | #define AUTOMAX 20 // Maximum seconds between sounds in auto mode | |
| 88 | //auto dome speeds, were -49 and 45, should be equal if using domegears | |
| 89 | - | #include <Wire.h> |
| 89 | + | #define DOMESPEEDL -30 // Speed that the dome will automatically spin left (negative) |
| 90 | - | #include <LiquidTWI.h> //this is the speedy i2C LCD library - get it here: http://forums.adafruit.com/viewtopic.php?f=19&t=21586 |
| 90 | + | #define DOMESPEEDR 30 // Speed that the dome will automatically spin right (negative) |
| 91 | - | LiquidTWI lcd(LCD); |
| 91 | + | |
| 92 | #define ATTEMPTS 25 // How many times to try and connect to the PS2 controller | |
| 93 | ||
| 94 | - | ////////////////////////////////////////////////////////////////// |
| 94 | + | #define BOARDTYPE 1 // 0 for regular Arduino, 1 for BotBoarduino (uses different PS2, ST & dome pins) |
| 95 | ||
| 96 | - | #if (MP3TRIGGERMODE==1) |
| 96 | + | byte drivespeed = drivespeed1; |
| 97 | - | SoftwareSerial trigSerial = SoftwareSerial(2, 3); |
| 97 | + | |
| 98 | ///////include libs and declare variables//////////////////////////// | |
| 99 | #include <Sabertooth.h> | |
| 100 | /*#if (SYRENMODE==3) | |
| 101 | Sabertooth SyR(128); | |
| 102 | #endif*/ | |
| 103 | #include <SoftwareSerial.h> | |
| 104 | #if (SYRENMODE==1) | |
| 105 | #include <SyRenSimplified.h> | |
| 106 | #endif | |
| 107 | #include <SyRenSimplified.h> | |
| 108 | #include <PS2X_lib.h> //for v1.7 | |
| 109 | #include <Servo.h> | |
| 110 | #include <MP3Trigger.h> | |
| 111 | #include <SoftEasyTransfer.h> | |
| 112 | #if defined(LCD) | |
| 113 | #include <Wire.h> | |
| 114 | #include <LiquidTWI.h> //this is the speedy i2C LCD library - get it here: http://forums.adafruit.com/viewtopic.php?f=19&t=21586 | |
| 115 | LiquidTWI lcd(LCD); | |
| 116 | #endif | |
| 117 | ||
| 118 | #if (MP3TRIGMODE==1) | |
| 119 | SoftwareSerial trigSerial = SoftwareSerial(2, 3); | |
| 120 | #endif | |
| 121 | MP3Trigger trigger; | |
| 122 | - | #include <Servo.h> |
| 122 | + | |
| 123 | Sabertooth SyR(128); | |
| 124 | #endif | |
| 125 | #if (BOARDTYPE==0) | |
| 126 | #if (SYRENMODE<3) | |
| 127 | SoftwareSerial SyRSerial(2, 5); | |
| 128 | #endif | |
| 129 | SoftwareSerial domeSerial(2, 8); | |
| 130 | SoftwareSerial STSerial(2, 7); | |
| 131 | #else | |
| 132 | - | int dsp; // 0 = random, 1 = alarm, 5 = leia, 11 = alarm2, 100 = no change |
| 132 | + | |
| 133 | - | }; |
| 133 | + | |
| 134 | #endif | |
| 135 | SoftwareSerial domeSerial(2, 10); | |
| 136 | SoftwareSerial STSerial(2, 13); | |
| 137 | #endif | |
| 138 | ||
| 139 | - | byte type = 0; // part of the ps2x lib |
| 139 | + | |
| 140 | - | byte vibrate = 0; // part of the ps2x lib |
| 140 | + | |
| 141 | - | byte vol = 40; // 0 = full volume, 64+ = inaudible, 255 = off |
| 141 | + | |
| 142 | #elif (SYRENMODE==2) | |
| 143 | Sabertooth SyR(128, SyRSerial); | |
| 144 | #endif | |
| 145 | - | byte automateDelay = random(5,20);// set this to min and max seconds between sounds |
| 145 | + | |
| 146 | - | int turnDirection = 20; |
| 146 | + | |
| 147 | struct SEND_DATA_STRUCTURE{
| |
| 148 | //put your variable definitions here for the data you want to send | |
| 149 | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO | |
| 150 | int hpx; // hp movement | |
| 151 | int hpy; // hp movement | |
| 152 | - | int domenumset = 0; //used for ramping in servo mode |
| 152 | + | |
| 153 | - | int domeramping=(ramping*4); |
| 153 | + | |
| 154 | int dsp; // 100=no change, 0=random, 1=alarm, 4=whistle, 5=leia, 6=short circut, 10=EQ, 11=alarm2, | |
| 155 | }; // 21=speed1, 22=speed2, 23=speed3, 24=logics+, 25=logics- | |
| 156 | ||
| 157 | SEND_DATA_STRUCTURE domeData;//give a name to the group of data | |
| 158 | ||
| 159 | PS2X ps2x; // create PS2 Controller Class | |
| 160 | int error = 0; // part of the ps2x lib | |
| 161 | //byte type = 0; // part of the ps2x lib | |
| 162 | //byte vibrate = 0; // part of the ps2x lib | |
| 163 | byte vol = 50; // 0 = full volume, 255 off | |
| 164 | - | lcd.begin(16, 2);// sets up the LCD's number of rows and columns |
| 164 | + | |
| 165 | - | lcd.clear(); |
| 165 | + | |
| 166 | unsigned long automateMillis = 0; | |
| 167 | - | delay(200); |
| 167 | + | byte automateDelay = random(AUTOMIN,AUTOMAX);// set this to min and max seconds between sounds |
| 168 | - | lcd.setBacklight(HIGH); |
| 168 | + | int turnDirection = 0; |
| 169 | - | delay(200); |
| 169 | + | |
| 170 | - | lcd.print("Starting up."); // Print a message to the LCD.
|
| 170 | + | |
| 171 | int drivenum = 0; | |
| 172 | - | delay(100); |
| 172 | + | |
| 173 | - | lcd.setBacklight(HIGH); |
| 173 | + | |
| 174 | int turnnum = 0; | |
| 175 | - | #if(SYRENMODE<3) |
| 175 | + | |
| 176 | byte lcdlight = 0; //used to toggle the LCD backlight on and off | |
| 177 | - | #endif |
| 177 | + | |
| 178 | ||
| 179 | - | SyR.motor(0); |
| 179 | + | |
| 180 | - | #elif(SYRENMODE==2) |
| 180 | + | |
| 181 | - | SyR.autobaud(); |
| 181 | + | |
| 182 | - | #elif(SYRENMODE==3) |
| 182 | + | #if defined(LCD) |
| 183 | - | SabertoothTXPinSerial.begin(domeBaudeRate); |
| 183 | + | lcd.begin(16, 2);// sets up the LCD's number of rows and columns |
| 184 | - | SyR.autobaud(); |
| 184 | + | lcd.clear(); |
| 185 | - | #endif |
| 185 | + | lcd.setBacklight(HIGH); |
| 186 | delay(50); | |
| 187 | lcd.print("Starting"); // Print a message to the LCD.
| |
| 188 | - | // NOTE: *Not all* Sabertooth controllers need this command. |
| 188 | + | lcd.setCursor(12,0); lcd.print(String(memoryFree())); |
| 189 | - | // It doesn't hurt anything, but V2 controllers use an |
| 189 | + | delay(500); |
| 190 | - | // EEPROM setting (changeable with the function setBaudRate) to set |
| 190 | + | |
| 191 | - | // the baud rate instead of detecting with autobaud. |
| 191 | + | |
| 192 | - | // |
| 192 | + | #if(SYRENMODE<3) |
| 193 | - | // If you have a 2x12, 2x25 V2, 2x60 or SyRen 50, you can remove |
| 193 | + | |
| 194 | - | // the autobaud line and save yourself two seconds of startup delay. |
| 194 | + | #endif |
| 195 | #if(SYRENMODE==1) | |
| 196 | SyR.motor(0); | |
| 197 | #elif(SYRENMODE==2) | |
| 198 | - | // mixes the two together to get diff-drive power levels for both motors. |
| 198 | + | SyR.autobaud(); |
| 199 | - | #if (MP3TRIGGERMODE==1) |
| 199 | + | #elif(SYRENMODE==3) |
| 200 | - | trigger.setup(&trigSerial); |
| 200 | + | SabertoothTXPinSerial.begin(domeBaudeRate); |
| 201 | - | trigSerial.begin( MP3Trigger::serialRate() ); |
| 201 | + | SyR.autobaud(); |
| 202 | #endif | |
| 203 | - | trigger.setup(&Serial); |
| 203 | + | |
| 204 | ST.autobaud(); // Send the autobaud command to the Sabertooth controller(s). | |
| 205 | // NOTE: *Not all* Sabertooth controllers need this command. | |
| 206 | // It doesn't hurt anything, but V2 controllers use an | |
| 207 | - | error = ps2x.config_gamepad(13,11,10,12, true, false); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error |
| 207 | + | // EEPROM setting (changeable with the function setBaudRate) to set |
| 208 | // the baud rate instead of detecting with autobaud. | |
| 209 | - | error = ps2x.config_gamepad(9,7,8,6, true, false); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error |
| 209 | + | // |
| 210 | // If you have a 2x12, 2x25 V2, 2x60 or SyRen 50, you can remove | |
| 211 | // the autobaud line and save yourself two seconds of startup delay. | |
| 212 | - | trigger.setVolume(vol);//anything with trigger. is for the mp3trigger |
| 212 | + | ST.setTimeout(950); |
| 213 | - | type = ps2x.readType(); |
| 213 | + | #if !defined(SYRENSIMPLE) |
| 214 | - | domeSerial.begin(57600);//start the library, pass in the data details and the name of the serial port. |
| 214 | + | SyR.setTimeout(950); |
| 215 | - | ET.begin(details(domeData), &domeSerial); |
| 215 | + | |
| 216 | ST.setDeadband(drivecompensation); | |
| 217 | ST.drive(0); // The Sabertooth won't act on mixed mode packet serial commands until | |
| 218 | ST.turn(0); // it has received power levels for BOTH throttle and turning, since it | |
| 219 | - | lcd.print("PADAWAN"); // Print a message to the LCD.
|
| 219 | + | // mixes the two together to get diff-drive power levels for both motors. |
| 220 | - | delay(250); |
| 220 | + | #if (MP3TRIGMODE==1) |
| 221 | trigger.setup(&trigSerial); | |
| 222 | trigSerial.begin( MP3Trigger::serialRate() ); | |
| 223 | #else | |
| 224 | trigger.setup(&Serial); | |
| 225 | #endif | |
| 226 | ||
| 227 | ||
| 228 | byte attempts=0; | |
| 229 | #if defined(LCD) | |
| 230 | - | lcd.print("Sound "+String(soundNumber)+" ");
|
| 230 | + | lcd.clear(); |
| 231 | lcd.print("PS2...");
| |
| 232 | lcd.setCursor(12,0); lcd.print(String(memoryFree())); | |
| 233 | delay(500); | |
| 234 | - | //////////////////////////////////////////////////////////////////////////////////////////// |
| 234 | + | #endif |
| 235 | trigger.setVolume(80); //set volume low for now | |
| 236 | - | ///////Loop run over and over////////////////////////////////////// |
| 236 | + | |
| 237 | - | ////////////////////////////////////////////////////////////////// |
| 237 | + | while(attempts<ATTEMPTS) { //loop around until a PS2 controller is found or we've attempted too many times
|
| 238 | //lcd.setCursor(12,0); lcd.print(String(memoryFree())); | |
| 239 | #if (BOARDTYPE==0) | |
| 240 | error = ps2x.config_gamepad(13,11,10,12, false, false); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error | |
| 241 | - | if(error == 1) //skip loop if no controller found |
| 241 | + | #else |
| 242 | - | return; |
| 242 | + | error = ps2x.config_gamepad(9,7,8,6, false, false); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error |
| 243 | #endif | |
| 244 | lcd.setCursor(12,0); lcd.print(String(memoryFree())); delay(500); | |
| 245 | if((error==0)||(error==3)) attempts=ATTEMPTS; //PS2 controller was found, or found with pressure disabled so we'll get out of this WHILE loop | |
| 246 | - | //// enable / disable right stick & play sound |
| 246 | + | #if defined(LCD) |
| 247 | - | if(ps2x.ButtonPressed(PSB_START)) |
| 247 | + | lcd.setCursor(12,1); lcd.print(String(attempts)+" "); |
| 248 | lcd.setCursor(0, 1); | |
| 249 | - | if (drive<1) |
| 249 | + | if(error == 0){
|
| 250 | lcd.print("found "); //found a PS2 controller
| |
| 251 | playSound(52); | |
| 252 | - | lcd.setCursor(0, 1); |
| 252 | + | } |
| 253 | - | lcd.print("-Drive Enabled-");
|
| 253 | + | else if(error == 1) {
|
| 254 | lcd.print("unfound"); //not found!
| |
| 255 | - | drive = 1; |
| 255 | + | //playSound(53); |
| 256 | ||
| 257 | - | } |
| 257 | + | } |
| 258 | - | else {
|
| 258 | + | else if(error == 2) {
|
| 259 | lcd.print("no cmds"); //found but not accepting commands
| |
| 260 | - | lcd.setCursor(0, 1); |
| 260 | + | //playSound(53); |
| 261 | - | lcd.print("-Drive Disabled-");
|
| 261 | + | } |
| 262 | else if(error == 3) {
| |
| 263 | - | drive = 0; |
| 263 | + | lcd.print("no pres"); //found but pressure not enabled
|
| 264 | - | playSound(53); |
| 264 | + | |
| 265 | - | } |
| 265 | + | } |
| 266 | #endif | |
| 267 | delay(100); | |
| 268 | - | ////turn hp automation or automate on & off |
| 268 | + | attempts++; |
| 269 | - | if(ps2x.ButtonPressed(PSB_SELECT)) {
|
| 269 | + | |
| 270 | ||
| 271 | - | if(ps2x.Button(PSB_R2)) {
|
| 271 | + | trigger.setVolume(vol);//set volume back to default value |
| 272 | - | if(domeData.hpa == 1) {
|
| 272 | + | //type = ps2x.readType(); |
| 273 | domeSerial.begin(57600);//start the library, pass in the data details and the name of the serial port. | |
| 274 | ET.begin(details(domeData), &domeSerial); | |
| 275 | - | lcd.print(" -Auto HP OFF- ");
|
| 275 | + | |
| 276 | - | #endif |
| 276 | + | |
| 277 | - | domeData.hpa = 0; |
| 277 | + | |
| 278 | - | domeData.dsp = 100; |
| 278 | + | #if defined(LCD) |
| 279 | - | ET.sendData(); |
| 279 | + | |
| 280 | //lcd.print("PADAWAN"); // Print a message to the LCD.
| |
| 281 | - | else {//if hp automation is off, turn it on
|
| 281 | + | //delay(100); |
| 282 | lcd.setBacklight(LOW); | |
| 283 | #endif | |
| 284 | - | lcd.print(" -Auto HP ON- ");
|
| 284 | + | |
| 285 | playSound(52); //play a sound to test things | |
| 286 | - | domeData.hpa = 1; |
| 286 | + | |
| 287 | - | domeData.dsp = 100; |
| 287 | + | } |
| 288 | - | ET.sendData(); |
| 288 | + | |
| 289 | - | }//turn hp automation off |
| 289 | + | // variables created by the build process when compiling the sketch (used for the memoryFree function) |
| 290 | - | } |
| 290 | + | extern int __bss_end; |
| 291 | extern void *__brkval; | |
| 292 | - | /////////////automate |
| 292 | + | // function to return the amount of free RAM |
| 293 | - | else {
|
| 293 | + | int memoryFree() {
|
| 294 | - | if (automate<1) {
|
| 294 | + | int freeValue; |
| 295 | if((int)__brkval == 0) freeValue = ((int)&freeValue) - ((int)&__bss_end); | |
| 296 | else freeValue = ((int)&freeValue) - ((int)__brkval); | |
| 297 | return freeValue; | |
| 298 | } | |
| 299 | ||
| 300 | ///////function to play sound (also outputs to LCD if connected)//////////////// | |
| 301 | void playSound(int soundNumber) {
| |
| 302 | #if defined(LCD) | |
| 303 | lcd.setCursor(0, 0); | |
| 304 | lcd.print("Snd"+String(soundNumber)+" ");
| |
| 305 | #endif | |
| 306 | trigger.play(soundNumber); | |
| 307 | - | automate = 0; |
| 307 | + | |
| 308 | - | action = 0; |
| 308 | + | //////////////////////////////////////////////////////////////////////////////////////////// |
| 309 | - | playSound(53); |
| 309 | + | |
| 310 | ///////Loop run over and over////////////////////////////////////// | |
| 311 | - | } |
| 311 | + | ////////////////////////////////////////////////////////////////// |
| 312 | ||
| 313 | void loop(){
| |
| 314 | - | if (automate == 1) |
| 314 | + | |
| 315 | - | {
|
| 315 | + | if(error == 1) //skip loop if no controller found |
| 316 | - | if (ps2x.Analog(PSS_LX)!=128) |
| 316 | + | |
| 317 | return; | |
| 318 | - | automateMillis = millis(); |
| 318 | + | |
| 319 | - | } |
| 319 | + | if(ps2x.Analog(PSS_RX) ==255 && ps2x.Analog(PSS_RY) ==255 && ps2x.Analog(PSS_LX)==255 &&ps2x.Analog(PSS_LY)==255) |
| 320 | - | unsigned long currentMillis = millis(); |
| 320 | + | {
|
| 321 | - | if (currentMillis - automateMillis > (automateDelay*1000)) |
| 321 | + | ST.drive(0); |
| 322 | ST.turn(0); | |
| 323 | - | automateMillis = millis(); |
| 323 | + | SyR.motor(1,0); |
| 324 | - | action = random(1,5); |
| 324 | + | return; |
| 325 | - | if (action>1) |
| 325 | + | } |
| 326 | - | {
|
| 326 | + | |
| 327 | - | (playSound(random(32,52))); |
| 327 | + | |
| 328 | //// enable / disable right stick & play sound | |
| 329 | - | if (action<4) |
| 329 | + | if(ps2x.ButtonPressed(PSB_START)) |
| 330 | - | {
|
| 330 | + | {if (drive<1)
|
| 331 | {
| |
| 332 | #if defined(LCD) | |
| 333 | lcd.setCursor(0, 1); | |
| 334 | lcd.print("-Drive Enabled-");
| |
| 335 | #endif | |
| 336 | drive = 1; playSound(52);} | |
| 337 | else {
| |
| 338 | #if defined(LCD) | |
| 339 | lcd.setCursor(0, 1); | |
| 340 | lcd.print("-Drive Disabled-");
| |
| 341 | #endif | |
| 342 | - | if (turnDirection>0) |
| 342 | + | drive = 0; playSound(53);} |
| 343 | - | {
|
| 343 | + | |
| 344 | - | turnDirection = -49; |
| 344 | + | |
| 345 | - | } |
| 345 | + | ////turn hp automation or automate on & off |
| 346 | - | else |
| 346 | + | if(ps2x.ButtonPressed(PSB_SELECT)) |
| 347 | - | {
|
| 347 | + | {if(ps2x.Button(PSB_R2))
|
| 348 | - | turnDirection = 45; |
| 348 | + | {if(domeData.hpa == 1)
|
| 349 | - | } |
| 349 | + | |
| 350 | #if defined(LCD) | |
| 351 | - | automateDelay = random(AUTOMIN,AUTOMAX);// set this to min and max seconds between sounds |
| 351 | + | lcd.setCursor(0, 1); |
| 352 | - | } |
| 352 | + | lcd.print(" -Auto HP OFF- ");
|
| 353 | #endif | |
| 354 | - | ////volume control |
| 354 | + | domeData.hpa = 0; domeData.dsp = 100; ET.sendData();}//if hp automation is off, turn it on |
| 355 | - | if(ps2x.Button(PSB_PAD_UP)) |
| 355 | + | |
| 356 | {
| |
| 357 | ||
| 358 | #if defined(LCD) | |
| 359 | - | if (vol>0) |
| 359 | + | lcd.setCursor(0, 1); |
| 360 | - | {
|
| 360 | + | lcd.print(" -Auto HP ON- ");
|
| 361 | - | vol=vol-VOLJUMP; |
| 361 | + | |
| 362 | - | if(vol<0) vol=0; |
| 362 | + | domeData.hpa = 1; domeData.dsp = 100; ET.sendData();}//turn hp automation off |
| 363 | } | |
| 364 | - | lcd.setCursor(9, 0); |
| 364 | + | |
| 365 | - | lcd.print("Vol "+String(vol)+" ");
|
| 365 | + | else |
| 366 | { if (automate<1) {
| |
| 367 | - | trigger.setVolume(vol); |
| 367 | + | |
| 368 | - | }// volume up |
| 368 | + | |
| 369 | lcd.print(" -Automate ON- ");
| |
| 370 | #endif | |
| 371 | automate = 1; | |
| 372 | playSound(52); | |
| 373 | } | |
| 374 | else {
| |
| 375 | - | if (vol<VOLLIMIT) |
| 375 | + | |
| 376 | - | {
|
| 376 | + | |
| 377 | - | vol=vol+VOLJUMP; |
| 377 | + | |
| 378 | - | if(vol>VOLLIMIT) vol=VOLLIMIT; |
| 378 | + | |
| 379 | automate = 0; action = 0; playSound(53);} | |
| 380 | - | lcd.setCursor(9, 0); |
| 380 | + | }} |
| 381 | - | lcd.print("Vol "+String(vol)+" ");
|
| 381 | + | |
| 382 | /////////////automate | |
| 383 | - | trigger.setVolume(vol); |
| 383 | + | if (automate == 1) |
| 384 | - | }//volume down |
| 384 | + | { if (ps2x.Analog(PSS_LX)!=128)
|
| 385 | - | } |
| 385 | + | { automateMillis = millis();}
|
| 386 | unsigned long currentMillis = millis(); | |
| 387 | if (currentMillis - automateMillis > (automateDelay*1000)) | |
| 388 | - | ////LCD backlight toggle on/off |
| 388 | + | {
|
| 389 | automateMillis = millis(); | |
| 390 | action = random(1,5); | |
| 391 | if (action>1) | |
| 392 | {
| |
| 393 | (playSound(random(32,52))); | |
| 394 | } | |
| 395 | if (action<4) | |
| 396 | {
| |
| 397 | #if (SYRENMODE==1) | |
| 398 | SyR.motor(turnDirection); | |
| 399 | #elif(SYRENMODE>=2) | |
| 400 | SyR.motor(1,turnDirection); | |
| 401 | #endif | |
| 402 | delay(750); | |
| 403 | #if(SYRENMODE==1) | |
| 404 | SyR.motor(0); | |
| 405 | #elif(SYRENMODE>=2) | |
| 406 | SyR.motor(1,0); | |
| 407 | #endif | |
| 408 | if (turnDirection>0) | |
| 409 | {turnDirection = DOMESPEEDL;}
| |
| 410 | - | /////hp movement |
| 410 | + | else |
| 411 | - | if(ps2x.ButtonPressed(PSB_PAD_UP)) |
| 411 | + | {turnDirection = DOMESPEEDR;}
|
| 412 | } | |
| 413 | - | if (!(ps2x.Button(PSB_R1))) |
| 413 | + | automateDelay = random(AUTOMIN,AUTOMAX);// set this to min and max seconds between sounds |
| 414 | }} | |
| 415 | - | domeData.hpy = 30; |
| 415 | + | ////volume controll |
| 416 | - | domeData.dsp = 100; |
| 416 | + | if(ps2x.Button(PSB_PAD_UP)) |
| 417 | - | ET.sendData(); |
| 417 | + | {
|
| 418 | - | } |
| 418 | + | if(ps2x.Button(PSB_R1)) |
| 419 | { if (vol>0)
| |
| 420 | - | if(ps2x.ButtonPressed(PSB_PAD_DOWN)) |
| 420 | + | {
|
| 421 | vol=vol-VOLJUMP; | |
| 422 | - | if (!(ps2x.Button(PSB_R1))) |
| 422 | + | if(vol<0) vol=0; |
| 423 | #if defined(LCD) | |
| 424 | - | domeData.hpy = 150; |
| 424 | + | lcd.setCursor(9, 0); |
| 425 | - | domeData.dsp = 100; |
| 425 | + | lcd.print("Vol "+String(vol)+" ");
|
| 426 | - | ET.sendData(); |
| 426 | + | #endif |
| 427 | - | } |
| 427 | + | trigger.setVolume(vol);}// volume up |
| 428 | } | |
| 429 | - | if(ps2x.ButtonReleased(PSB_PAD_UP)||ps2x.ButtonReleased(PSB_PAD_DOWN)) |
| 429 | + | } |
| 430 | if(ps2x.Button(PSB_PAD_DOWN)) | |
| 431 | - | domeData.hpy = 0; |
| 431 | + | |
| 432 | - | domeData.dsp = 100; |
| 432 | + | if(ps2x.Button(PSB_R1)) |
| 433 | - | ET.sendData(); |
| 433 | + | { if (vol<VOLLIMIT)
|
| 434 | {
| |
| 435 | vol=vol+VOLJUMP; | |
| 436 | - | if(ps2x.ButtonPressed(PSB_PAD_RIGHT)) |
| 436 | + | if(vol>VOLLIMIT) vol=VOLLIMIT; |
| 437 | #if defined(LCD) | |
| 438 | - | domeData.hpx = 150; |
| 438 | + | lcd.setCursor(9, 0); |
| 439 | - | domeData.dsp = 100; |
| 439 | + | lcd.print("Vol "+String(vol)+" ");
|
| 440 | - | ET.sendData(); |
| 440 | + | #endif |
| 441 | trigger.setVolume(vol);}//volume down | |
| 442 | - | if(ps2x.ButtonPressed(PSB_PAD_LEFT)) |
| 442 | + | } |
| 443 | } | |
| 444 | - | domeData.hpx = 30; |
| 444 | + | |
| 445 | - | domeData.dsp = 100; |
| 445 | + | ////LCD backlight toggle on/off |
| 446 | - | ET.sendData(); |
| 446 | + | |
| 447 | if(ps2x.Button(PSB_PAD_LEFT)) | |
| 448 | - | if(ps2x.ButtonReleased(PSB_PAD_RIGHT)||ps2x.ButtonReleased(PSB_PAD_LEFT)) |
| 448 | + | |
| 449 | if(ps2x.Button(PSB_R1)) | |
| 450 | - | domeData.hpx = 0; |
| 450 | + | |
| 451 | - | domeData.dsp = 100; |
| 451 | + | |
| 452 | - | ET.sendData(); |
| 452 | + | |
| 453 | lcd.setBacklight(HIGH); | |
| 454 | lcdlight=1; | |
| 455 | } | |
| 456 | - | /////play sounds and change display |
| 456 | + | |
| 457 | { //turn off backlight
| |
| 458 | lcd.setBacklight(LOW); | |
| 459 | - | if(ps2x.Button(PSB_L1)) |
| 459 | + | |
| 460 | } | |
| 461 | - | (playSound(8)); |
| 461 | + | |
| 462 | - | domeData.dsp = 0; |
| 462 | + | |
| 463 | - | ET.sendData(); |
| 463 | + | |
| 464 | - | } |
| 464 | + | |
| 465 | ////Logic display brightness | |
| 466 | if(ps2x.ButtonPressed(PSB_PAD_UP)) | |
| 467 | - | (playSound(2)); |
| 467 | + | {
|
| 468 | - | domeData.dsp = 0; |
| 468 | + | if(ps2x.Button(PSB_L1)) |
| 469 | - | ET.sendData(); |
| 469 | + | {
|
| 470 | - | } |
| 470 | + | domeData.dsp = 24; ET.sendData(); |
| 471 | } | |
| 472 | } | |
| 473 | - | (playSound(9)); |
| 473 | + | if(ps2x.ButtonPressed(PSB_PAD_DOWN)) |
| 474 | - | domeData.dsp = 0; |
| 474 | + | |
| 475 | - | ET.sendData(); |
| 475 | + | if(ps2x.Button(PSB_L1)) |
| 476 | - | } |
| 476 | + | {
|
| 477 | - | else |
| 477 | + | domeData.dsp = 25; ET.sendData(); |
| 478 | } | |
| 479 | - | (playSound(random(13,17))); |
| 479 | + | } |
| 480 | - | domeData.dsp = 0; |
| 480 | + | |
| 481 | - | ET.sendData(); |
| 481 | + | |
| 482 | - | } |
| 482 | + | /////hp movement |
| 483 | if(ps2x.ButtonPressed(PSB_PAD_UP)) | |
| 484 | {if (!((ps2x.Button(PSB_R1))||(ps2x.Button(PSB_L1))))
| |
| 485 | {
| |
| 486 | - | if(ps2x.Button(PSB_L1)) |
| 486 | + | domeData.hpy = 30; domeData.dsp = 100; ET.sendData(); |
| 487 | }} | |
| 488 | - | (playSound(6)); |
| 488 | + | if(ps2x.ButtonPressed(PSB_PAD_DOWN)) |
| 489 | - | domeData.dsp = 0; |
| 489 | + | {if (!((ps2x.Button(PSB_R1))||(ps2x.Button(PSB_L1))))
|
| 490 | - | ET.sendData(); |
| 490 | + | {
|
| 491 | - | } |
| 491 | + | domeData.hpy = 150; domeData.dsp = 100; ET.sendData(); |
| 492 | }} | |
| 493 | if(ps2x.ButtonReleased(PSB_PAD_UP)||ps2x.ButtonReleased(PSB_PAD_DOWN)) | |
| 494 | - | (playSound(1)); |
| 494 | + | {domeData.hpy = 0; domeData.dsp = 100; ET.sendData();}
|
| 495 | - | domeData.dsp = 1; |
| 495 | + | |
| 496 | - | ET.sendData(); |
| 496 | + | if(ps2x.ButtonPressed(PSB_PAD_RIGHT)) |
| 497 | - | domeData.dsp = 0; |
| 497 | + | {
|
| 498 | - | } |
| 498 | + | domeData.hpx = 150; domeData.dsp = 100; ET.sendData(); |
| 499 | } | |
| 500 | if(ps2x.ButtonPressed(PSB_PAD_LEFT)) | |
| 501 | - | (playSound(11)); |
| 501 | + | {
|
| 502 | - | domeData.dsp = 11; |
| 502 | + | domeData.hpx = 30; domeData.dsp = 100; ET.sendData(); |
| 503 | - | ET.sendData(); |
| 503 | + | } |
| 504 | - | domeData.dsp = 0; |
| 504 | + | if(ps2x.ButtonReleased(PSB_PAD_RIGHT)||ps2x.ButtonReleased(PSB_PAD_LEFT)) |
| 505 | - | } |
| 505 | + | {domeData.hpx = 0; domeData.dsp = 100; ET.sendData();}
|
| 506 | - | else |
| 506 | + | |
| 507 | ||
| 508 | - | (playSound(random(17,25))); |
| 508 | + | /////play sounds and change display |
| 509 | - | domeData.dsp = 0; |
| 509 | + | |
| 510 | - | ET.sendData(); |
| 510 | + | {if(ps2x.Button(PSB_L1))
|
| 511 | - | } |
| 511 | + | {(playSound(8)); domeData.dsp = 0; ET.sendData();}
|
| 512 | else if(ps2x.Button(PSB_L2)) | |
| 513 | {(playSound(2)); domeData.dsp = 0; ET.sendData();}
| |
| 514 | else if(ps2x.Button(PSB_R1)) | |
| 515 | - | if(ps2x.Button(PSB_L1)) |
| 515 | + | {(playSound(9)); domeData.dsp = 0; ET.sendData();}
|
| 516 | else if(ps2x.Button(PSB_R2)) | |
| 517 | - | (playSound(7)); |
| 517 | + | { // PLAY EXTRA/CUSTOM SOUND FILE
|
| 518 | - | domeData.dsp = 0; |
| 518 | + | (playSound(57)); domeData.dsp = 0; ET.sendData();} |
| 519 | - | ET.sendData(); |
| 519 | + | else |
| 520 | - | } |
| 520 | + | {(playSound(random(13,17))); domeData.dsp = 0; ET.sendData();}}
|
| 521 | if(ps2x.ButtonPressed(PSB_BLUE))//x bottom | |
| 522 | {if(ps2x.Button(PSB_L1))
| |
| 523 | - | (playSound(3)); |
| 523 | + | {(playSound(6)); domeData.dsp = 6; ET.sendData();}
|
| 524 | - | domeData.dsp = 0; |
| 524 | + | |
| 525 | - | ET.sendData(); |
| 525 | + | {(playSound(1)); domeData.dsp = 1; ET.sendData(); domeData.dsp = 0;}
|
| 526 | - | } |
| 526 | + | |
| 527 | {(playSound(11)); domeData.dsp = 11; ET.sendData(); domeData.dsp = 0;}
| |
| 528 | else if(ps2x.Button(PSB_R2)) | |
| 529 | - | (playSound(10)); |
| 529 | + | { // PLAY EXTRA/CUSTOM SOUND FILE
|
| 530 | - | domeData.dsp = 0; |
| 530 | + | (playSound(random(56,65))); domeData.dsp = 0; ET.sendData();} // random lemur sound (total of 9) |
| 531 | - | ET.sendData(); |
| 531 | + | else |
| 532 | - | } |
| 532 | + | {(playSound(random(17,25))); domeData.dsp = 0; ET.sendData();}}
|
| 533 | - | else |
| 533 | + | |
| 534 | {if(ps2x.Button(PSB_L1))
| |
| 535 | - | (playSound(random(32,52))); |
| 535 | + | {(playSound(7)); domeData.dsp = 0; ET.sendData();}
|
| 536 | - | domeData.dsp = 0; |
| 536 | + | |
| 537 | - | ET.sendData(); |
| 537 | + | {(playSound(3)); domeData.dsp = 0; ET.sendData();}
|
| 538 | - | } |
| 538 | + | |
| 539 | {(playSound(10)); domeData.dsp = 10; ET.sendData();}
| |
| 540 | else if(ps2x.Button(PSB_R2)) | |
| 541 | { // PLAY EXTRA/CUSTOM SOUND FILE
| |
| 542 | - | if(ps2x.Button(PSB_L1)) |
| 542 | + | (playSound(55)); domeData.dsp = 0; ET.sendData();} |
| 543 | else | |
| 544 | - | (playSound(5)); |
| 544 | + | {(playSound(random(32,52))); domeData.dsp = 0; ET.sendData();}}
|
| 545 | - | domeData.dsp = 5; |
| 545 | + | |
| 546 | - | ET.sendData(); |
| 546 | + | {if(ps2x.Button(PSB_L1))
|
| 547 | - | domeData.dsp = 0; |
| 547 | + | {(playSound(5)); domeData.dsp = 5; ET.sendData(); domeData.dsp = 0;}
|
| 548 | - | } |
| 548 | + | |
| 549 | {(playSound(4)); domeData.dsp = 4; ET.sendData();}
| |
| 550 | else if(ps2x.Button(PSB_R1)) | |
| 551 | - | (playSound(4)); |
| 551 | + | {(playSound(12)); domeData.dsp = 0; ET.sendData();}
|
| 552 | - | domeData.dsp = 0; |
| 552 | + | else if(ps2x.Button(PSB_R2)) |
| 553 | - | ET.sendData(); |
| 553 | + | { // PLAY EXTRA/CUSTOM SOUND FILE
|
| 554 | - | } |
| 554 | + | (playSound(54)); domeData.dsp = 0; ET.sendData();} |
| 555 | else | |
| 556 | {(playSound(random(25,32))); domeData.dsp = 0; ET.sendData();}}
| |
| 557 | - | (playSound(12)); |
| 557 | + | |
| 558 | - | domeData.dsp = 0; |
| 558 | + | ////turn hp light on & off |
| 559 | - | ET.sendData(); |
| 559 | + | |
| 560 | - | } |
| 560 | + | |
| 561 | - | else |
| 561 | + | |
| 562 | {domeData.hpl = 0; domeData.dsp = 100; ET.sendData();}//if hp light is on, turn it off
| |
| 563 | - | (playSound(random(25,32))); |
| 563 | + | |
| 564 | - | domeData.dsp = 0; |
| 564 | + | {domeData.hpl = 1; domeData.dsp = 100; ET.sendData();}//turn hp light on
|
| 565 | - | ET.sendData(); |
| 565 | + | |
| 566 | - | } |
| 566 | + | |
| 567 | ////Change drivespeed | |
| 568 | if(ps2x.ButtonPressed(PSB_R3)) //right joystick | |
| 569 | - | ////turn hp light on & off |
| 569 | + | {
|
| 570 | if(drivespeed == drivespeed1)//if in lowest speed | |
| 571 | {
| |
| 572 | #if defined(LCD) | |
| 573 | lcd.setCursor(0, 1); lcd.print("- Medium Speed -");
| |
| 574 | - | domeData.hpl = 0; |
| 574 | + | |
| 575 | - | domeData.dsp = 100; |
| 575 | + | drivespeed = drivespeed2; playSound(53);domeData.dsp = 22; ET.sendData(); domeData.dsp = 0;}//change to medium speed and play sound 3-tone |
| 576 | - | ET.sendData(); |
| 576 | + | else if(drivespeed == drivespeed2 && (drivespeed3!=0))//if in medium speed |
| 577 | - | }//if hp light is on, turn it off |
| 577 | + | {
|
| 578 | #if defined(LCD) | |
| 579 | lcd.setCursor(0, 1); lcd.print("- *HIGH SPEED* -");
| |
| 580 | - | domeData.hpl = 1; |
| 580 | + | |
| 581 | - | domeData.dsp = 100; |
| 581 | + | drivespeed = drivespeed3; playSound(1);domeData.dsp = 23; ET.sendData(); domeData.dsp = 0;}//change to high speed and play sound scream |
| 582 | - | ET.sendData(); |
| 582 | + | else////////////////////////////////////////we must be in high speed |
| 583 | - | }//turn hp light on |
| 583 | + | {
|
| 584 | #if defined(LCD) | |
| 585 | lcd.setCursor(0, 1); lcd.print("- Slow Speed -");
| |
| 586 | - | /////foot drives |
| 586 | + | |
| 587 | - | /////////////////new stuff////////////////// |
| 587 | + | drivespeed = drivespeed1; playSound(52);domeData.dsp = 21; ET.sendData(); domeData.dsp = 0;}//change to low speed and play sound 2-tone |
| 588 | - | sticknum = (map(ps2x.Analog(PSS_RY), 0, 255, -drivespeed, drivespeed)); |
| 588 | + | } |
| 589 | ||
| 590 | - | if (drivenum < sticknum) |
| 590 | + | /////foot drives |
| 591 | /////////////////new stuff////////////////// | |
| 592 | - | if (sticknum-drivenum<(ramping+1)) |
| 592 | + | sticknum = (map(ps2x.Analog(PSS_RY), 0, 255, -drivespeed, drivespeed)); |
| 593 | - | drivenum+=ramping; |
| 593 | + | |
| 594 | if (drivenum < sticknum) | |
| 595 | - | drivenum = sticknum; |
| 595 | + | {
|
| 596 | if (sticknum-drivenum<(ramping+1)) | |
| 597 | drivenum+=ramping; | |
| 598 | else | |
| 599 | - | else if (drivenum > sticknum) |
| 599 | + | drivenum = sticknum; |
| 600 | ||
| 601 | - | if (drivenum-sticknum<(ramping+1)) |
| 601 | + | } |
| 602 | - | drivenum-=ramping; |
| 602 | + | |
| 603 | else if (drivenum > sticknum) | |
| 604 | - | drivenum = sticknum; |
| 604 | + | {
|
| 605 | if (drivenum-sticknum<(ramping+1)) | |
| 606 | drivenum-=ramping; | |
| 607 | else | |
| 608 | drivenum = sticknum; | |
| 609 | - | turnnum = (ps2x.Analog(PSS_RX)); |
| 609 | + | |
| 610 | - | if (turnnum <= 200 && turnnum >= 54) |
| 610 | + | } |
| 611 | - | turnnum = (map(ps2x.Analog(PSS_RX), 54, 200, -(turnspeed/3), (turnspeed/3))); |
| 611 | + | |
| 612 | - | else if (turnnum > 200) |
| 612 | + | |
| 613 | - | turnnum = (map(ps2x.Analog(PSS_RX), 201, 255, turnspeed/3, turnspeed)); |
| 613 | + | turnnum = (ps2x.Analog(PSS_RX)); |
| 614 | - | else if (turnnum < 54) |
| 614 | + | if (turnnum <= 200 && turnnum >= 54) |
| 615 | - | turnnum = (map(ps2x.Analog(PSS_RX), 0, 53, -turnspeed, -(turnspeed/3))); |
| 615 | + | turnnum = (map(ps2x.Analog(PSS_RX), 54, 200, -(turnspeed/3), (turnspeed/3))); |
| 616 | else if (turnnum > 200) | |
| 617 | - | ////////////////////////////////// |
| 617 | + | turnnum = (map(ps2x.Analog(PSS_RX), 201, 255, turnspeed/3, turnspeed)); |
| 618 | else if (turnnum < 54) | |
| 619 | - | {
|
| 619 | + | turnnum = (map(ps2x.Analog(PSS_RX), 0, 53, -turnspeed, -(turnspeed/3))); |
| 620 | ||
| 621 | - | /*lcd.setCursor(6, 1); |
| 621 | + | ////////////////////////////////// |
| 622 | - | lcd.print("Tu"+String(turnnum)+" Dr"+String(drivenum)+" ");*/
|
| 622 | + | |
| 623 | {
| |
| 624 | - | ST.turn(turnnum); |
| 624 | + | ST.turn(turnnum); |
| 625 | - | ST.drive(drivenum); |
| 625 | + | ST.drive(drivenum); |
| 626 | } | |
| 627 | ||
| 628 | - | /////dome drive |
| 628 | + | /////dome drive |
| 629 | - | domenum = (map(ps2x.Analog(PSS_LX), 0, 255, -domespeed, domespeed)); |
| 629 | + | domenum = (map(ps2x.Analog(PSS_LX), 0, 255, -domespeed, domespeed)); |
| 630 | - | if (domenum > domecompensation && domenum < domecompensation) domenum = 0; |
| 630 | + | if (domenum > -domecompensation && domenum < domecompensation) |
| 631 | domenum = 0; | |
| 632 | #if defined(LCD) | |
| 633 | lcd.setCursor(0, 1); | |
| 634 | lcd.print("Sy"+String(domenum)+" ");
| |
| 635 | #endif | |
| 636 | #if(SYRENMODE==1) | |
| 637 | SyR.motor(domenum); | |
| 638 | #elif(SYRENMODE>=2) | |
| 639 | SyR.motor(1,domenum); | |
| 640 | #endif | |
| 641 | ||
| 642 | - | //////////// |
| 642 | + | //////////// |
| 643 | - | delay(50); |
| 643 | + | delay(50); |
| 644 | } | |
| 645 | ///////////////////////////////////////////////////////////////// | |
| 646 | ////////////////////////////////////////////////////////////////// |