Advertisement
joymonkey

Padawan Body code 1.1.14 w/LCD & Options

Apr 24th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // =======================================================================================
  2. // /////////////////////////Padawan Body Code ////////////////////////////////////////////
  3. // =======================================================================================
  4. //                                 danf
  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. //
  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. //   Extra sounds triggered by R2 + Square=54  Circle=55  X=56  Triangle=57
  38. //
  39. //         This program is free software: you can redistribute it and/or modify it .
  40. //         This program is distributed in the hope that it will be useful,
  41. //         but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. //         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  43. //
  44. //************************** Set speed and turn here************************************//
  45.  
  46. #define drivespeed1  75 //set these 3 to whatever speeds work for you. 0=stop, 127=full speed.
  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. #define turnspeed 50    // the higher this number the faster it will spin in place, lower - easier to controll.
  51.                         // Recommend beginner: 40 to 50, experienced: 50 $ up, I like 75
  52.                        
  53. #define domespeed 110   // If using a speed controller for the dome, sets the top speed
  54.                         // Use a number up to 127 for serial
  55.                        
  56. #define ramping 5       // Ramping- the lower this number the longer R2 will take to speedup or slow down,
  57.                         // change this by incriments of 1
  58.                        
  59. #define MP3TRIGMODE 1   // 0 for regular mode (MP3 Tirgger RX connects to Pin 1)
  60.                         // 1 for Software Serial mode (MP3 Trigger connects to Pin 3)
  61.  
  62. #define SYRENMODE 3     // 1=Simple Serial , 2=Packetized Software Serial (recommended), 3=Packetized Hardware Serial (S1 connects to Pin 1)
  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 domecompensation 0  // For controllers that centering problems, causing slight dome drift in one direction
  67.  
  68. #define drivecompensation 0  // use the lowest number with no drift
  69.                              // (this sets the Sabertooth's Deadband and will persist between restarts)
  70.                              // Motor powers in the range [-deadband, deadband] will be considered in the deadband,
  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.  
  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. #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. #define DOMESPEEDL -30  // Speed that the dome will automatically spin left (negative)
  90. #define DOMESPEEDR 30   // Speed that the dome will automatically spin right (negative)
  91.  
  92. #define ATTEMPTS 25   // How many times to try and connect to the PS2 controller
  93.  
  94. #define BOARDTYPE 1   // 0 for regular Arduino, 1 for BotBoarduino (uses different PS2, ST & dome pins)    
  95.  
  96. byte drivespeed = drivespeed1;                 
  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. #if (SYRENMODE==3)
  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.   #if (SYRENMODE<3)
  133.   SoftwareSerial SyRSerial(2, 11);
  134.   #endif
  135.   SoftwareSerial domeSerial(2, 10);
  136.   SoftwareSerial STSerial(2, 13);
  137. #endif
  138.  
  139. Sabertooth ST(128, STSerial);
  140. #if (SYRENMODE==1)
  141. SyRenSimplified SyR(SyRSerial); // Use SWSerial as the serial port.
  142. #elif (SYRENMODE==2)
  143. Sabertooth SyR(128, SyRSerial);
  144. #endif
  145. SoftEasyTransfer ET;//create object
  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 hpl; // hp light
  153.   int hpa; // hp automation
  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. byte drive = 0; // 0 = drive motors off ( right stick disabled )
  165. byte automate = 0;
  166. unsigned long automateMillis = 0;
  167. byte automateDelay = random(AUTOMIN,AUTOMAX);// set this to min and max seconds between sounds
  168. int turnDirection = 0;
  169. byte action = 0;
  170. unsigned long DriveMillis = 0;
  171. int drivenum = 0;
  172. int sticknum = 0;
  173. int domenum = 0;
  174. int turnnum = 0;
  175. #if defined(LCD)  
  176. byte lcdlight = 0; //used to toggle the LCD backlight on and off
  177. #endif
  178.  
  179. //////////////set up run once//////////////////////////////////////////
  180.  
  181. void setup(){
  182.   #if defined(LCD)  
  183.       lcd.begin(16, 2);// sets up the LCD's number of rows and columns  
  184.       lcd.clear();
  185.       lcd.setBacklight(HIGH);
  186.       delay(50);
  187.       lcd.print("Starting"); // Print a message to the LCD.
  188.           lcd.setCursor(12,0); lcd.print(String(memoryFree()));          
  189.           delay(500);
  190.   #endif
  191.    
  192.   #if(SYRENMODE<3)
  193.   SyRSerial.begin(domeBaudeRate);
  194.   #endif  
  195.   #if(SYRENMODE==1)
  196.    SyR.motor(0);            
  197.   #elif(SYRENMODE==2)
  198.    SyR.autobaud();
  199.   #elif(SYRENMODE==3)
  200.    SabertoothTXPinSerial.begin(domeBaudeRate);
  201.    SyR.autobaud();
  202.   #endif
  203.   STSerial.begin(9600);   // 9600 is the default baud rate for Sabertooth packet serial.
  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.                           //       EEPROM setting (changeable with the function setBaudRate) to set
  208.                           //       the baud rate instead of detecting with autobaud.
  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.   ST.setTimeout(950);
  213.   #if !defined(SYRENSIMPLE)
  214.   SyR.setTimeout(950);
  215.   #endif
  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.                // mixes the two together to get diff-drive power levels for both motors.
  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.clear();
  231.    lcd.print("PS2...");
  232.    lcd.setCursor(12,0); lcd.print(String(memoryFree()));  
  233.    delay(500);
  234.    #endif
  235.    trigger.setVolume(80); //set volume low for now
  236.    
  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.    #else
  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.    #if defined(LCD)
  247.    lcd.setCursor(12,1); lcd.print(String(attempts)+" ");
  248.    lcd.setCursor(0, 1);
  249.    if(error == 0){
  250.        lcd.print("found  "); //found a PS2 controller
  251.        playSound(52);
  252.    }  
  253.    else if(error == 1) {
  254.       lcd.print("unfound"); //not found!
  255.       //playSound(53);
  256.      
  257.    }  
  258.    else if(error == 2) {
  259.       lcd.print("no cmds"); //found but not accepting commands
  260.       //playSound(53);
  261.    }
  262.    else if(error == 3) {
  263.       lcd.print("no pres"); //found but pressure not enabled
  264.       playSound(52);
  265.    }
  266.    #endif
  267.    delay(100);
  268.    attempts++;
  269.   }  
  270.  
  271.  trigger.setVolume(vol);//set volume back to default value
  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.  
  276.  
  277.  
  278.  #if defined(LCD)  
  279.   lcd.clear();    
  280.   //lcd.print("PADAWAN"); // Print a message to the LCD.
  281.   //delay(100);
  282.   lcd.setBacklight(LOW);
  283.  #endif
  284.  
  285.  playSound(52); //play a sound to test things
  286.  
  287.  }
  288.  
  289. // variables created by the build process when compiling the sketch (used for the memoryFree function)
  290. extern int __bss_end;
  291. extern void *__brkval;
  292. // function to return the amount of free RAM
  293. int memoryFree() {
  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. }
  308. ////////////////////////////////////////////////////////////////////////////////////////////  
  309.  
  310.  ///////Loop run over and over//////////////////////////////////////
  311.  //////////////////////////////////////////////////////////////////
  312.  
  313. void loop(){
  314.    
  315.  if(error == 1) //skip loop if no controller found
  316.  
  317.   return;
  318.  
  319.   if(ps2x.Analog(PSS_RX) ==255 && ps2x.Analog(PSS_RY) ==255 && ps2x.Analog(PSS_LX)==255 &&ps2x.Analog(PSS_LY)==255)
  320.  {
  321.   ST.drive(0);
  322.   ST.turn(0);
  323.   SyR.motor(1,0);
  324.   return;
  325.  }
  326.   ps2x.read_gamepad();   //read controller and set large motor to spin at 'vibrate' speed
  327.  
  328.  //// enable / disable right stick & play sound
  329.  if(ps2x.ButtonPressed(PSB_START))
  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.  drive = 0; playSound(53);}
  343. }
  344.  
  345.  ////turn hp automation or automate on & off      
  346.  if(ps2x.ButtonPressed(PSB_SELECT))
  347.   {if(ps2x.Button(PSB_R2))
  348.    {if(domeData.hpa == 1)
  349.     {
  350. #if defined(LCD)
  351.     lcd.setCursor(0, 1);
  352.     lcd.print(" -Auto HP OFF-  ");
  353. #endif  
  354.     domeData.hpa = 0; domeData.dsp = 100; ET.sendData();}//if hp automation is off, turn it on
  355.     else
  356.     {
  357.    
  358. #if defined(LCD)
  359.     lcd.setCursor(0, 1);
  360.     lcd.print("  -Auto HP ON-  ");
  361. #endif  
  362.     domeData.hpa = 1; domeData.dsp = 100; ET.sendData();}//turn hp automation off
  363.   }
  364.  
  365. else
  366. {      if (automate<1) {
  367. #if defined(LCD)
  368.         lcd.setCursor(0, 1);
  369.         lcd.print(" -Automate  ON-  ");
  370. #endif
  371.         automate = 1;
  372.         playSound(52);
  373.       }
  374.       else {
  375. #if defined(LCD)
  376.         lcd.setCursor(0, 1);
  377.         lcd.print(" -Automate OFF- ");
  378. #endif
  379. automate = 0; action = 0; playSound(53);}
  380. }}
  381.  
  382. /////////////automate
  383. if (automate == 1)
  384. { if (ps2x.Analog(PSS_LX)!=128)
  385.   { automateMillis = millis();}
  386.   unsigned long currentMillis = millis();
  387.    if (currentMillis - automateMillis > (automateDelay*1000))
  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.    else
  411.       {turnDirection = DOMESPEEDR;}
  412.   }
  413.   automateDelay = random(AUTOMIN,AUTOMAX);// set this to min and max seconds between sounds
  414. }}
  415. ////volume controll
  416.  if(ps2x.Button(PSB_PAD_UP))
  417.  {
  418.   if(ps2x.Button(PSB_R1))
  419.    { if (vol>0)
  420.    {
  421.    vol=vol-VOLJUMP;
  422.    if(vol<0) vol=0;
  423.     #if defined(LCD)
  424.         lcd.setCursor(9, 0);
  425.         lcd.print("Vol "+String(vol)+"  ");
  426.     #endif
  427.    trigger.setVolume(vol);}// volume up
  428.    }  
  429.  }
  430.   if(ps2x.Button(PSB_PAD_DOWN))
  431.   {
  432.   if(ps2x.Button(PSB_R1))
  433.    { if (vol<VOLLIMIT)
  434.    {
  435.    vol=vol+VOLJUMP;
  436.    if(vol>VOLLIMIT) vol=VOLLIMIT;
  437.    #if defined(LCD)
  438.      lcd.setCursor(9, 0);
  439.      lcd.print("Vol "+String(vol)+"  ");
  440.    #endif  
  441.    trigger.setVolume(vol);}//volume down
  442.    }
  443.  }
  444.  
  445. ////LCD backlight toggle on/off
  446. #if defined(LCD)
  447.   if(ps2x.Button(PSB_PAD_LEFT))
  448.   {
  449.     if(ps2x.Button(PSB_R1))
  450.     {
  451.       if (lcdlight==0)
  452.       { //turn on backlight
  453.         lcd.setBacklight(HIGH);
  454.         lcdlight=1;
  455.       }
  456.       else
  457.       { //turn off backlight
  458.         lcd.setBacklight(LOW);
  459.         lcdlight=0;
  460.       }
  461.     }  
  462.   }
  463. #endif
  464.  
  465.  ////Logic display brightness
  466.  if(ps2x.ButtonPressed(PSB_PAD_UP))
  467.  {
  468.   if(ps2x.Button(PSB_L1))
  469.    {
  470.      domeData.dsp = 24; ET.sendData();
  471.    }  
  472.  }
  473.   if(ps2x.ButtonPressed(PSB_PAD_DOWN))
  474.   {
  475.   if(ps2x.Button(PSB_L1))
  476.    {
  477.      domeData.dsp = 25; ET.sendData();
  478.    }
  479.  }
  480.  
  481.  
  482.  /////hp movement
  483. if(ps2x.ButtonPressed(PSB_PAD_UP))
  484. {if (!((ps2x.Button(PSB_R1))||(ps2x.Button(PSB_L1))))
  485.  {
  486.    domeData.hpy = 30; domeData.dsp = 100; ET.sendData();
  487.  }}
  488.  if(ps2x.ButtonPressed(PSB_PAD_DOWN))
  489. {if (!((ps2x.Button(PSB_R1))||(ps2x.Button(PSB_L1))))
  490.  {
  491.    domeData.hpy = 150; domeData.dsp = 100; ET.sendData();
  492.  }}
  493.  if(ps2x.ButtonReleased(PSB_PAD_UP)||ps2x.ButtonReleased(PSB_PAD_DOWN))
  494.  {domeData.hpy = 0; domeData.dsp = 100; ET.sendData();}
  495.  
  496.  if(ps2x.ButtonPressed(PSB_PAD_RIGHT))
  497.  {
  498.    domeData.hpx = 150; domeData.dsp = 100; ET.sendData();
  499.  }
  500.  if(ps2x.ButtonPressed(PSB_PAD_LEFT))
  501.  {
  502.    domeData.hpx = 30; domeData.dsp = 100; ET.sendData();
  503.  }
  504.  if(ps2x.ButtonReleased(PSB_PAD_RIGHT)||ps2x.ButtonReleased(PSB_PAD_LEFT))
  505.  {domeData.hpx = 0; domeData.dsp = 100; ET.sendData();}
  506.  
  507.  
  508.  /////play sounds and change display
  509.   if(ps2x.ButtonPressed(PSB_GREEN))//triangle top
  510.    {if(ps2x.Button(PSB_L1))
  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.       {(playSound(9)); domeData.dsp = 0; ET.sendData();}
  516.     else if(ps2x.Button(PSB_R2))
  517.       { // PLAY EXTRA/CUSTOM SOUND FILE
  518.         (playSound(57)); domeData.dsp = 0; ET.sendData();}    
  519.      else
  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(6)); domeData.dsp = 6; ET.sendData();}
  524.     else if(ps2x.Button(PSB_L2))
  525.       {(playSound(1)); domeData.dsp = 1; ET.sendData(); domeData.dsp = 0;}
  526.     else if(ps2x.Button(PSB_R1))
  527.       {(playSound(11)); domeData.dsp = 11; ET.sendData(); domeData.dsp = 0;}
  528.     else if(ps2x.Button(PSB_R2))
  529.       { // PLAY EXTRA/CUSTOM SOUND FILE
  530.         (playSound(random(56,65))); domeData.dsp = 0; ET.sendData();}    // random lemur sound (total of 9)
  531.      else
  532.       {(playSound(random(17,25))); domeData.dsp = 0; ET.sendData();}}
  533.   if(ps2x.ButtonPressed(PSB_RED))//circle right
  534.    {if(ps2x.Button(PSB_L1))
  535.       {(playSound(7)); domeData.dsp = 0; ET.sendData();}
  536.     else if(ps2x.Button(PSB_L2))
  537.       {(playSound(3)); domeData.dsp = 0; ET.sendData();}
  538.     else if(ps2x.Button(PSB_R1))
  539.       {(playSound(10)); domeData.dsp = 10; ET.sendData();}
  540.     else if(ps2x.Button(PSB_R2))
  541.       { // PLAY EXTRA/CUSTOM SOUND FILE      
  542.         (playSound(55)); domeData.dsp = 0; ET.sendData();}    
  543.      else
  544.       {(playSound(random(32,52))); domeData.dsp = 0; ET.sendData();}}
  545.   if(ps2x.ButtonPressed(PSB_PINK))//square left
  546.    {if(ps2x.Button(PSB_L1))
  547.       {(playSound(5)); domeData.dsp = 5; ET.sendData(); domeData.dsp = 0;}
  548.     else if(ps2x.Button(PSB_L2))
  549.       {(playSound(4)); domeData.dsp = 4; ET.sendData();}
  550.     else if(ps2x.Button(PSB_R1))
  551.       {(playSound(12)); domeData.dsp = 0; ET.sendData();}
  552.     else if(ps2x.Button(PSB_R2))
  553.       { // PLAY EXTRA/CUSTOM SOUND FILE
  554.         (playSound(54)); domeData.dsp = 0; ET.sendData();}  
  555.      else
  556.       {(playSound(random(25,32))); domeData.dsp = 0; ET.sendData();}}
  557.    
  558.  ////turn hp light on & off      
  559.   if(ps2x.ButtonPressed(PSB_L3)) //left joystick
  560.   {
  561.     if(domeData.hpl == 1)
  562.     {domeData.hpl = 0; domeData.dsp = 100; ET.sendData();}//if hp light is on, turn it off
  563.     else
  564.     {domeData.hpl = 1; domeData.dsp = 100; ET.sendData();}//turn hp light on
  565.   }  
  566.  
  567.  ////Change drivespeed
  568. if(ps2x.ButtonPressed(PSB_R3)) //right joystick
  569. {
  570. if(drivespeed == drivespeed1)//if in lowest speed
  571. {
  572. #if defined(LCD)
  573.     lcd.setCursor(0, 1); lcd.print("- Medium Speed -");
  574. #endif
  575. drivespeed = drivespeed2; playSound(53);domeData.dsp = 22; ET.sendData(); domeData.dsp = 0;}//change to medium speed and play sound 3-tone
  576. else if(drivespeed == drivespeed2 && (drivespeed3!=0))//if in medium speed
  577. {
  578. #if defined(LCD)
  579.     lcd.setCursor(0, 1); lcd.print("- *HIGH SPEED* -");
  580. #endif
  581. drivespeed = drivespeed3; playSound(1);domeData.dsp = 23; ET.sendData(); domeData.dsp = 0;}//change to high speed and play sound scream
  582. else////////////////////////////////////////we must be in high speed
  583. {
  584. #if defined(LCD)
  585.     lcd.setCursor(0, 1); lcd.print("-  Slow Speed  -");
  586. #endif
  587. drivespeed = drivespeed1; playSound(52);domeData.dsp = 21; ET.sendData(); domeData.dsp = 0;}//change to low speed and play sound 2-tone
  588. }
  589.    
  590.  /////foot drives
  591. /////////////////new stuff//////////////////
  592. sticknum = (map(ps2x.Analog(PSS_RY), 0, 255, -drivespeed, drivespeed));
  593.  
  594.    if (drivenum < sticknum)
  595.    {
  596.      if (sticknum-drivenum<(ramping+1))
  597.      drivenum+=ramping;
  598.      else
  599.      drivenum = sticknum;
  600.  
  601.    }
  602.      
  603.    else if (drivenum > sticknum)
  604.    {
  605.      if (drivenum-sticknum<(ramping+1))
  606.      drivenum-=ramping;
  607.      else
  608.      drivenum = sticknum;
  609.  
  610.    }
  611.  
  612.  
  613.  turnnum = (ps2x.Analog(PSS_RX));  
  614.  if (turnnum <= 200 && turnnum >= 54)
  615.   turnnum = (map(ps2x.Analog(PSS_RX), 54, 200, -(turnspeed/3), (turnspeed/3)));
  616.  else if (turnnum > 200)
  617.   turnnum = (map(ps2x.Analog(PSS_RX), 201, 255, turnspeed/3, turnspeed));
  618.  else if (turnnum < 54)
  619.   turnnum = (map(ps2x.Analog(PSS_RX), 0, 53, -turnspeed, -(turnspeed/3)));
  620.  
  621. //////////////////////////////////
  622.   if (drive == 1)// right stick (drive)
  623. {  
  624.   ST.turn(turnnum);
  625.   ST.drive(drivenum);
  626. }
  627.  
  628. /////dome drive
  629. domenum = (map(ps2x.Analog(PSS_LX), 0, 255, -domespeed, domespeed));
  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. ////////////
  643.  delay(50);
  644. }
  645. /////////////////////////////////////////////////////////////////
  646. //////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement