Jump to content

Ghostchips

Members
  • Posts

    4869
  • Joined

  • Days Won

    5

Posts posted by Ghostchips

  1.  

    // constants won't change. Used here to set a pin number:
    const int coil1 = 3;
    const int coil2 = 5;
    const int coil3 = 7;
    const int coil4 = 9;

    const int sensorPin1 = A4;
    const int sensorPin2 = A1;
    const int sensorPin3 = A2;
    const int sensorPin4 = A3;

    int sensorValue = 0;

    int sensorThreshold = 200;
    int sensorMax = 0;

    // Variables will change:
    volatile int coilState = LOW;
    volatile int coilPin = LOW;

    volatile int sparkTriggerDelayActive = false;     //added this to try & see if i can delay spark at low RPM.
    volatile int sparkTriggerDelay = 0;
    volatile unsigned long rpmCurrMicros= 0;
    volatile unsigned long rpmOldMicros = 0;
    volatile int sensor1TriggerCounter = 0;           // counter for the number of button presses
    volatile int sensorTriggerState = false;         // current state of the button
    volatile int lastsensorTriggerState = true;     // previous state  of the button/sensor in this case.

    // constants won't change:
    // Generally, you should use "unsigned long" for variables that hold time
    // The value will quickly become too large for an int to store

    const long dwell = 10;        // but this is how long the "points" are open, open longer reduces duty cycle of coils.

    // constants won't change:
    const long coilCharge = 2;           // interval at which to charge coil (milliseconds)

    void setup() {
      // put your setup code here, to run once:
      Serial.begin(115200);
      pinMode(coil1, OUTPUT);
      pinMode(coil2, OUTPUT);
      pinMode(coil3, OUTPUT);
      pinMode(coil4, OUTPUT);
      pinMode(A4, INPUT_PULLUP);
      pinMode(A1, INPUT_PULLUP);
      pinMode(A2, INPUT_PULLUP);
      pinMode(A3, INPUT_PULLUP);
    }

    void activateCoilsIfLow(uint8_t inPin, uint8_t outPin)
    {
     volatile unsigned long timestamp = 0;
       if (analogRead(inPin) <= sensorThreshold)
       sensorTriggerState = true;
       {
        if (lastsensorTriggerState = false)
        {
          timestamp = micros();
          if ((timestamp + sparkTriggerDelay) >= micros())
          {
            lastsensorTriggerState = true;
          }
        }
        else if (lastsensorTriggerState = true && analogRead(inPin) <= sensorThreshold)
         {
          coilState = HIGH;
          coilPin = HIGH;
          digitalWrite(outPin, HIGH);
        
          timestamp = millis();
                                              
          while (coilState == HIGH && coilPin == HIGH && (timestamp + coilCharge) > millis());  //Busy wait
       
         digitalWrite(outPin, LOW);
          coilPin = LOW;
          timestamp = millis();

          while (coilState == HIGH && coilPin == LOW && (timestamp + dwell) > millis());
     
          coilState = LOW;
          coilPin = LOW;
        }
      }
      else if (analogRead(inPin) >= sensorThreshold)
      {
        sensorTriggerState = false;
        if (sensorTriggerState != lastsensorTriggerState)
        {
          rpmOldMicros = rpmCurrMicros;
          rpmCurrMicros = micros();
          lastsensorTriggerState = false;
          rpmConsultRatioTable();
        }
      }
    }

    void loop() {
      activateCoilsIfLow(sensorPin1, coil1);
      activateCoilsIfLow(sensorPin3, coil3);
      activateCoilsIfLow(sensorPin2, coil4);
      activateCoilsIfLow(sensorPin4, coil2);
    }

    void rpmConsultRatioTable()
    {
      if (rpmCurrMicros - rpmOldMicros >= 497512) //sub250rpm
        {
          sparkTriggerDelay =0;
        }
      else if ((rpmCurrMicros - rpmOldMicros <= 255024) && (rpmCurrMicros - rpmOldMicros >= 169491)) //125rpm
        {
          sparkTriggerDelay =81000;                     //was 57, then 59
          Serial.print ( "RPM 125" );
        }
      else if ((rpmCurrMicros - rpmOldMicros <= 169491) && (rpmCurrMicros - rpmOldMicros >= 127512)) //177rpm
        {
          sparkTriggerDelay =39000;
          Serial.print ( "RPM 177.5" );
        }
      else if ((rpmCurrMicros - rpmOldMicros <= 127512) && (rpmCurrMicros - rpmOldMicros >= 85008)) //250rpm
        {
          sparkTriggerDelay =32000;                    //was 27  //at 250 RPM and 45 degree sensor advance, this would be 30ms to TDC, subtract 2ms for coil charging and subtract more m.s. for advance
          Serial.print ( "RPM 250" );
        }
      else if ((rpmCurrMicros - rpmOldMicros <= 85008) && (rpmCurrMicros - rpmOldMicros >= 61000)) //375rpm
        {
          sparkTriggerDelay =18000;                 //was 16
          Serial.print ( "RPM 375" );
        }
      else if ((rpmCurrMicros - rpmOldMicros <= 61000) && (rpmCurrMicros - rpmOldMicros >= 48000)) //500rpm
        {
          sparkTriggerDelay =13000;                 //was 11
          Serial.print ( "RPM 500" );
        }
      else if ((rpmCurrMicros - rpmOldMicros <= 48000) && (rpmCurrMicros - rpmOldMicros >= 41000))  //625rpm
        {
          sparkTriggerDelay =7000;
          Serial.print ( "RPM 625" );
        }
      else if ((rpmCurrMicros - rpmOldMicros <= 41000) && (rpmCurrMicros - rpmOldMicros >= 31500)) //750rpm
        {
          sparkTriggerDelay =1670;
          Serial.print ( "RPM 750" );
        }
      else if (rpmCurrMicros - rpmOldMicros <= 31500) //just under 1000rpm
        {
          sparkTriggerDelay =0;
          Serial.print ( "RPM over 1000" );
        }
    }


    If i increment the math side of things by 100 it stays at full advance all the time.  By 1,000 - 10,000, same thing.  It even advances while sitting there not turning over, but will retard while running.
    Please tell me how bad my math is.

    • Like 2
  2. Don't mind this, it's just a basic, primitive tune i spent the afternoon adjusting

    // constants won't change. Used here to set a pin number:
    const int coil1 = 3;
    const int coil2 = 5;
    const int coil3 = 7;
    const int coil4 = 9;
    
    const int sensorPin1 = A4;
    const int sensorPin2 = A1;
    const int sensorPin3 = A2;
    const int sensorPin4 = A3;
    
    int sensorValue = 0;
    
    int sensorThreshold = 200;
    int sensorMax = 0;
    
    // Variables will change:
    volatile int coilState = LOW;
    volatile int coilPin = LOW;
    
    volatile int sparkTriggerDelayActive = false;     //added this to try & see if i can delay spark at low RPM.
    volatile int sparkTriggerDelay = 0;
    volatile unsigned long rpmCurrMicros= 0;
    volatile unsigned long rpmOldMicros = 0;
    volatile int sensor1TriggerCounter = 0;           // counter for the number of button presses
    volatile int sensorTriggerState = false;         // current state of the button
    volatile int lastsensorTriggerState = true;     // previous state  of the button/sensor in this case.
    
    // constants won't change:
    // Generally, you should use "unsigned long" for variables that hold time
    // The value will quickly become too large for an int to store
    
    const long dwell = 10;        // but this is how long the "points" are open, open longer reduces duty cycle of coils.
    
    // constants won't change:
    const long coilCharge = 2;           // interval at which to charge coil (milliseconds)
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      pinMode(coil1, OUTPUT);
      pinMode(coil2, OUTPUT);
      pinMode(coil3, OUTPUT);
      pinMode(coil4, OUTPUT);
      pinMode(A4, INPUT_PULLUP);
      pinMode(A1, INPUT_PULLUP);
      pinMode(A2, INPUT_PULLUP);
      pinMode(A3, INPUT_PULLUP);
    }
    
    void activateCoilsIfLow(uint8_t inPin, uint8_t outPin)
    {
     volatile unsigned long timestamp = 0;
     sensorTriggerState = true;
       if (analogRead(inPin) <= sensorThreshold)
       {
        if (lastsensorTriggerState = (false))
        {
          delay(sparkTriggerDelay);
          lastsensorTriggerState = true;
        }
        else
         {
          coilState = HIGH;
          coilPin = HIGH;
          digitalWrite(outPin, HIGH);
        
          timestamp = millis();
                                              
          while (coilState == HIGH && coilPin == HIGH && (timestamp + coilCharge) > millis());  //Busy wait
       
         digitalWrite(outPin, LOW);
          coilPin = LOW;
          timestamp = millis();
    
          while (coilState == HIGH && coilPin == LOW && (timestamp + dwell) > millis());
     
          coilState = LOW;
          coilPin = LOW;
        }
      }
      else if (analogRead(inPin) >= sensorThreshold)
      {
        sensorTriggerState = false;
        if (sensorTriggerState != lastsensorTriggerState)
        {
          rpmOldMicros = rpmCurrMicros;
          rpmCurrMicros = micros();
          lastsensorTriggerState = false;
          rpmConsultRatioTable();
        }
      }
    }
    
    void loop() {
      activateCoilsIfLow(sensorPin1, coil1);
      activateCoilsIfLow(sensorPin3, coil3);
      activateCoilsIfLow(sensorPin2, coil4);
      activateCoilsIfLow(sensorPin4, coil2);
    }
    
    void rpmConsultRatioTable()
    {
      if (rpmCurrMicros - rpmOldMicros >= 497512) //sub250rpm
        {
          sparkTriggerDelay =0;
        }
      else if (rpmCurrMicros - rpmOldMicros <= 255024) //125rpm
        {
          sparkTriggerDelay =57;                   //prev'55  
        }
      else if (rpmCurrMicros - rpmOldMicros <= 169491) //177rpm
        {
          sparkTriggerDelay =39;                   //prev' 37
        }
      else if (rpmCurrMicros - rpmOldMicros <= 127512) //250rpm
        {
          sparkTriggerDelay =27;                      //at 250 RPM and 45 degree sensor advance, this would be 30ms to TDC, subtract 2ms for coil charging and subtract more m.s. for advance
        }
      else if (rpmCurrMicros - rpmOldMicros <= 85008) //375rpm
        {
          sparkTriggerDelay =16;
        }
      else if (rpmCurrMicros - rpmOldMicros <= 61000) //500rpm
        {
          sparkTriggerDelay =11;
        }
      else if (rpmCurrMicros - rpmOldMicros <= 48000)  //625rpm
        {
          sparkTriggerDelay =7;
        }
      else if (rpmCurrMicros - rpmOldMicros <= 41000) //750rpm
        {
          sparkTriggerDelay =2;
        }
      else if (rpmCurrMicros - rpmOldMicros <= 31500) //just under 1000rpm
        {
          sparkTriggerDelay =0;
        }
    }

    Posting this here so i can find it later if i'm not home.
    Side note: i am probably the only person using milliseconds to determine when to fire the plug compared to using actual degrees.

    • Like 7
    • Thanks 1
  3. If you're asking how much of the closing face needs to be lapped to fit.  It should have a minimum ring, if the seat is cut on 2 angles and the valve face would be lapped for maybe half a mill' or so?
    Reason being that sharp edge cuts through carbon, but is still wide enough to dissipate heat.

    Obviously i do 1-2 mm on my dinosaurs so maybe you shouldn't take my advice.

    Or i answered a different question altogether.

    • Like 2
  4. Not sure how to test the frequency of the main loop without an oscilloscope so i had it serial print for 30 seconds.
    Which told me the baud rate was the limiting factor.
    E.G.

     

    current milliseconds0


    current loop count1
    current milliseconds0
    current loop count2
    current milliseconds1
    current loop count3
    current milliseconds2
    current loop count4
    current milliseconds2
    current loop count5
    current milliseconds3
    current loop count6
    current milliseconds7
    current loop count7
    current milliseconds19
    current loop count8
    current milliseconds33
    current loop count9
    .......................

    current milliseconds20272
    current loop count1124
    current milliseconds20291
    current loop count1125
    current milliseconds20311
    current loop count1126
    current milliseconds20331

    At 9600


    Versus

    Edit: what happened to the text with the other rate ect?

    Anyhow. adding "coilState = LOW" in the 'else' statement has transformed the open road running.  Work much like i intended  (Duhh what an oversight that was!)


    Would drive fine.  But it's now hard to start & misses at 120-500 RPM?  Can't figure that one out.

     

    • Like 1
  5. Edit: Forgot to mention this is a nano 328P about 16.000hrtz?  If that makes a difference to the way it runs.
    So.. this 

     
    
    // constants won't change. Used here to set a pin number:
    const int coil1 = 3;
    const int coil2 = 5;
    const int coil3 = 7;
    const int coil4 = 9;
    
    const int sensorPin1 = A4;
    const int sensorPin2 = A1;
    const int sensorPin3 = A2;
    const int sensorPin4 = A3;
    
    int sensorValue = 0;
    
    int sensorThreshold = 200;
    int sensorMax = 0; 
    
    // Variables will change:
    volatile int coilState = LOW;
    volatile int coilPin = LOW;
    
    volatile unsigned long currentMicros;
    volatile unsigned long previousMicros = 0;        // will store last time LED was updated
    
    
    // constants won't change:
    const long interval = 1000;    
      
    // Generally, you should use "unsigned long" for variables that hold time
    // The value will quickly become too large for an int to store
    
    unsigned long dwell = 6000;        // will store last time LED was updated
    
    // constants won't change:
    const long coilCharge = 2000;           // interval at which to charge coil (Microseconds)
    
    void setup() {
      // put your setup code here, to run once:
      pinMode(coil1, OUTPUT);
      pinMode(coil2, OUTPUT);
      pinMode(coil3, OUTPUT);
      pinMode(coil4, OUTPUT);
      pinMode(A4, INPUT_PULLUP);
      pinMode(A1, INPUT_PULLUP);
      pinMode(A2, INPUT_PULLUP);
      pinMode(A3, INPUT_PULLUP);
    }
    
    void activateCoilsIfLow(uint8_t inPin, uint8_t outPin)
    {
     volatile unsigned long currentMicros = micros();
        
      if (analogRead(inPin) <= sensorThreshold)
      {
          while (coilState == LOW && coilPin == LOW) {
          coilState = HIGH;
          coilPin = HIGH;
          digitalWrite(outPin, !(digitalRead(outPin)));
          previousMicros = currentMicros;
         }
        while (coilState == HIGH && coilPin == HIGH && currentMicros - previousMicros >= coilCharge)
         {
          digitalWrite(outPin, LOW);
          coilPin = LOW;
          previousMicros = currentMicros;
         }
        while (coilState == HIGH && coilPin == LOW && currentMicros - previousMicros >= dwell)
        {
          previousMicros = currentMicros;
          coilState = LOW;
          coilPin = LOW;
        }
      }
      else
      {
        digitalWrite(outPin, LOW);
      }
    }
    
    void loop() {
    
      activateCoilsIfLow(sensorPin1, coil1);
      activateCoilsIfLow(sensorPin3, coil3);
      activateCoilsIfLow(sensorPin2, coil4);
      activateCoilsIfLow(sensorPin4, coil2);
    }


    runs really weird on manual advance mode, seems to lag at certain RPM, then suddenly the timing will become accurate for a slightly higher RPM, then lag for the few RPM above that.
    Revving stationary it'll be fine at idle to ...1100RPM?  cough & pop out the carb' until 1700 RPM.
    On the road you can feel it lurching at cruise speeds, each time the RPM rises or falls across that threshold that spans maybe... 10RPM layers where the lag disappears & re-appears, judging from the exhaust sound and gas temp' gauge reading 50-70 degrees above normal it's running retarded.  Feels like a cross between riding a horse and "Run out of gas & sloshing the last bit of fuel in the carb' bowl over the main jet" surging.
    At 1600-1700 RPM or so it'll lose that lag & fire on time every time, feels like someone hit Vtec.
    Tried changing micros to millis ect, same effect.  6,000 worked better than 10,000 micros.

    Meanwhile. This crappy delay code will run perfectly.  But doesn't have any advance/retard (and if i tried to add that i'd lose lots of time to calculate it due to the delay...)

     
    
    
    const int sensorPin1 = A4;
    const int sensorPin2 = A1;
    const int sensorPin3 = A2;
    const int sensorPin4 = A3;
    int sensorValue = 0;
    
    int sensorThreshold = 200;
    int sensorMax = 0; 
    
    void setup() {
      pinMode(3, OUTPUT);
      pinMode(5, OUTPUT);
      pinMode(7, OUTPUT);
      pinMode(9, OUTPUT);
      pinMode(A4, INPUT_PULLUP);
      pinMode(A1, INPUT_PULLUP);
      pinMode(A2, INPUT_PULLUP);
      pinMode(A3, INPUT_PULLUP);
    }
    
    void activateCoilsIfLow(uint8_t inPin, uint8_t outPin)
    {
      if (analogRead(inPin) <= sensorThreshold)
      {
        digitalWrite(outPin, !(digitalRead(outPin)));
        delay(2);
        digitalWrite(outPin, LOW);
        delay(10);
      }
      else
      {
        digitalWrite(outPin, LOW);
      }
    }
    
    void loop()
    {
    
      activateCoilsIfLow(sensorPin1, 3);
      activateCoilsIfLow(sensorPin3, 7);
      activateCoilsIfLow(sensorPin2, 9);
      activateCoilsIfLow(sensorPin4, 5);
    }
    • Like 2
  6. On 07/11/2019 at 18:11, tortron said:

    Also want to hear lol

     

    Is there a decent led replacement for a motorcycle tail/brake light bulb. My incandescent only lasted 6 months

    If it was vibration i once used a jandel  based gasket to isolate the vibrations from a tail light on a read guard on someones bike.  They loved it (it'd blow in 30 minutes prior to my jandle).
    Either that or just some random mixed LED of ali' should go the job (bought 5 kinds for the price of one from repco and all 5 came) for what it's worth the purple ones show brighter through red glass than red ones, as long as you don't need a license plate light from that same bulb.

    • Like 1
  7. I can wind the mixture screw in 1/8th and not melt the pistons.

    i also made a music player for summer.


    basicMP3.jpg.bf623a3b1594e75e43dd165c6b567c14.jpg

     

    The first one, had no support for remembering where it stopped playing when it was turned off & i didn't want to stress the EEPROM by writing to it every time you changed a song.
    So i made this hilarious work around.
    254766597_basicMP32.jpg.cfbb7b7db618b47e861bd8a0ef0ce538.jpg

    The first one, had no support for remembering where it stopped playing when it was turned off & i didn't want to stress the EEPROM by writing to it every time you changed a song.
    So i made this hilarious work around.
    Ultra capacitors running the player for a few seconds after it is turned off.

    /***************************************************
     * A basic MP3 player for a car, that was never designed for a radio.
     * connect to an amplifier for enhanced sound.  Anything better than the single MOSFET i used should be fine.
     * in this version i attempted to overcome its habit of not playing the next track, but i don't know how to read the 'Finished playing' from the serial... 
     * I derived this code from ...
     * 
     DFPlayer - A Mini MP3 Player For Arduino
     <https://www.dfrobot.com/index.php?route=product/product&product_id=1121>
    
     ***************************************************
     This example shows the all the function of library for DFPlayer.
    
     Created 2016-12-07
     By [Angelo qiao](Angelo.qiao@dfrobot.com)
    
     GNU Lesser General Public License.
     See <http://www.gnu.org/licenses/> for details.
     All above must be included in any redistribution
     ****************************************************/
    
    /***********Notice and Trouble shooting***************
     1.Connection and Diagram can be found here
    <https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram>
     2.This code is tested on Arduino Uno, Leonardo, Mega boards.
     ****************************************************/
    
    #include "Arduino.h"
    #include "SoftwareSerial.h"
    #include "DFRobotDFPlayerMini.h"
    
    # define ACTIVATED LOW
    
    SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
    DFRobotDFPlayerMini myDFPlayer;
    void printDetail(uint8_t type, int value);
    int buttonPause = 3;
    int buttonVolPlus = 4;
    int buttonVolMinus = 2;
    int buttonNext = 6;
    int buttonPrev = 7;
    int buttonFolderNext = 8;
    int buttonFolderPrev = 5;
    int theReadStatus = 0;
    long unsigned theReadStatusTimer = 0;
    int currentFileNumber = 1;
    int busyReadPin = A1;
    int readCurrentFileNumber(uint8_t device);
    long unsigned currentMillis = 0;
    int thisChar;
    
    boolean isPlaying = true;
    
    int trackCount = 0;   
    int oldtrackCount = 0;     
    int folderCount = 0;   
    int oldfolderCount = 0;
    
    String inputString = "";         // a String to hold incoming data
    bool stringComplete = false;  // whether the string is complete
    
    void setup()
    {
    
      
    # define Start_Byte 0x7E
    # define Version_Byte 0xFF
    # define Command_Length 0x06
    # define End_Byte 0xEF
    # define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
    
      pinMode(buttonPause, INPUT);
      digitalWrite(buttonPause,HIGH);
    
      pinMode(buttonVolPlus, INPUT);
       digitalWrite(buttonVolPlus,HIGH);
    
      pinMode(buttonVolMinus, INPUT);
      digitalWrite(buttonVolMinus,HIGH);
    
      pinMode(buttonNext, INPUT);
      digitalWrite(buttonNext,HIGH);
    
      pinMode(buttonPrev, INPUT);
      digitalWrite(buttonPrev,HIGH);
    
      pinMode(buttonFolderNext, INPUT);
      digitalWrite(buttonFolderNext,HIGH);
    
      pinMode(buttonFolderPrev, INPUT);
      digitalWrite(buttonFolderPrev,HIGH);
    
      pinMode(busyReadPin, INPUT);
      digitalWrite(busyReadPin,LOW);
    
      mySoftwareSerial.begin(9600);
      Serial.begin(9600);
      
        while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
      inputString.reserve(200);   // reserve 200 bytes for the inputString:
      
      Serial.println();
      Serial.println(F("DFRobot DFPlayer Mini Demo"));
      Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
    
      if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
        Serial.println(F("Unable to begin:"));
        Serial.println(F("1.Please recheck the connection!"));
        Serial.println(F("2.Please insert the SD card!"));
        while(true);
      }
      Serial.println(F("DFPlayer Mini online."));
    
      myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
    
      //----Set volume----
      myDFPlayer.volume(05);  //Set volume value (0~30).
      myDFPlayer.volumeUp(); //Volume Up
      myDFPlayer.volumeDown(); //Volume Down
      myDFPlayer.play(1);
    
      //----Set different EQ----
      myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
    //  myDFPlayer.EQ(DFPLAYER_EQ_POP);
    //  myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
    //  myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
    //  myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
    //  myDFPlayer.EQ(DFPLAYER_EQ_BASS);
    
      //----Set device we use SD as default----
    //  myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK);
      myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
    //  myDFPlayer.outputDevice(DFPLAYER_DEVICE_AUX);
    //  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SLEEP);
    //  myDFPlayer.outputDevice(DFPLAYER_DEVICE_FLASH);
    
      //----Mp3 control----
    //  myDFPlayer.sleep();     //sleep
    //  myDFPlayer.reset();     //Reset the module
    //  myDFPlayer.enableDAC();  //Enable On-chip DAC
    //  myDFPlayer.disableDAC();  //Disable On-chip DAC
    //  myDFPlayer.outputSetting(true, 15); //output setting, enable the output and set the gain to 15
    
    
      //----Read imformation----
      Serial.println(myDFPlayer.readState()); //read mp3 state
      Serial.println(myDFPlayer.readVolume()); //read current volume
      Serial.println(myDFPlayer.readEQ()); //read EQ setting
      Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
      Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
      Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read fill counts in folder SD:/03
    
      isPlaying = true;
      myDFPlayer.enableLoopAll();
    }
    
    void loop()
    {
     if (digitalRead(buttonPause) == ACTIVATED)
      {
        if(isPlaying)
        {
          Serial.print( " Paused " );
          delay(20);
          myDFPlayer.pause();
          isPlaying = false;
        }
        else
        {
          Serial.print( " Play " );
          delay(20);
          isPlaying = true;
          myDFPlayer.start();
        }
      }
      delay(20);
    
     if (digitalRead(buttonVolPlus) == ACTIVATED)
      {
        if(isPlaying)
        {
          Serial.print( " Vol-Up " );
          myDFPlayer.volumeUp();
          delay(10);
        }
      }
    
      if (digitalRead(buttonVolMinus) == ACTIVATED)
      {
          Serial.print( " Vol-Down " );
          myDFPlayer.volumeDown();
          delay(10);
      }
    
     if (digitalRead(buttonNext) == ACTIVATED)
      {
        if(isPlaying)
        {
          Serial.print( " Button Next " );
          trackCount++;
          myDFPlayer.next();
          delay(20);
        }
      }
    
      if (digitalRead(buttonPrev) == ACTIVATED)
      {
        if(isPlaying)
        {
          Serial.print( " Button Prev' " );
          myDFPlayer.previous();
          trackCount--;
          delay(20);
        }
      }
    
     if (digitalRead(buttonFolderNext) == ACTIVATED)
      {
        if(isPlaying)
        {
          Serial.print( " Button folder+ " );
          folderCount++;
          Serial.print(folderCount);
          folderChange();
          delay(20);
        }
      }
    
      if (digitalRead(buttonFolderPrev) == ACTIVATED)
      {
        if(isPlaying)
        {
          Serial.print( " Button folder- " );
          folderCount--;
          Serial.print(folderCount);
          folderChange();
          delay(20);
        }
      }
    
      if (myDFPlayer.available())
      {
        printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
      }
      while (myDFPlayer.available())
      {
        char inChar = ((char)(myDFPlayer.read()));                    //This method is a work-around for me being too dumb.
        Serial.print(myDFPlayer.readType(), myDFPlayer.read());       //I'm too dumb to figure out ho to read the "play finished" output as a string?
        if (inChar != 0)                                              //So i came up with this, Disgusting! it's just using any data while playing to 'auto-next'.
            if(isPlaying)                                             //Even interference from a spark plug could trigger this.  Shield your wires?
            {
             Serial.print( " Auto-Button Next " );
             trackCount++;
             myDFPlayer.next();
             delay(20);
             inChar = 0;
            }
      }
      
      delay(120);
    }
    
    void folderChange()
    {
      if (folderCount == 1) {
        myDFPlayer.play((5));
        Serial.print(" 5 ");
      }
      else if (folderCount == 2) {
        myDFPlayer.play((10 + trackCount));
        Serial.print(" 10 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 3) {
        myDFPlayer.play((15 + trackCount));
        Serial.print(" 15 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 4) {
        myDFPlayer.play((20 + trackCount));
        Serial.print(" 20 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 5) {
        myDFPlayer.play((25 + trackCount));
        Serial.print(" 25 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 6) {
        myDFPlayer.play((30 + trackCount));
        Serial.print(" 30 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 7) {
        myDFPlayer.play((35 + trackCount));
        Serial.print(" 35 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 8) {
        myDFPlayer.play((40 + trackCount));
        Serial.print(" 40 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 9) {
        myDFPlayer.play((45 + trackCount));
        Serial.print(" 45 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 10) {
        myDFPlayer.play((50 + trackCount));
        Serial.print(" 50 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 11) {
        myDFPlayer.play((55 + trackCount));
        Serial.print(" 55 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 12) {
        myDFPlayer.play((60 + trackCount));
        Serial.print(" 60 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 13) {
        myDFPlayer.play((65 + trackCount));
        Serial.print(" 65 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 14) {
        myDFPlayer.play((70 + trackCount));
        Serial.print(" 70 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 15) {
        myDFPlayer.play((75 + trackCount));
        Serial.print(" 75 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 16) {
        myDFPlayer.play((80 + trackCount));
        Serial.print(" 80 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 17) {
        myDFPlayer.play((85 + trackCount));
        Serial.print(" 85 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 18) {
        myDFPlayer.play((90 + trackCount));
        Serial.print(" 90 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 19) {
        myDFPlayer.play((95 + trackCount));
        Serial.print(" 95 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 20) {
        myDFPlayer.play((100 + trackCount));
        Serial.print(" 100 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 21) {
        myDFPlayer.play((105 + trackCount));
        Serial.print(" 105 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 22) {
        myDFPlayer.play((110 + trackCount));
        Serial.print(" 110 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 23) {
        myDFPlayer.play((115 + trackCount));
        Serial.print(" 115 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 24) {
        myDFPlayer.play((120 + trackCount));
        Serial.print(" 120 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 25) {
        myDFPlayer.play((125 + trackCount));
        Serial.print(" 125 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 26) {
        myDFPlayer.play((130 + trackCount));
        Serial.print(" 130 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 27) {
        myDFPlayer.play((135 + trackCount));
        Serial.print(" 135 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 28) {
        myDFPlayer.play((140 + trackCount));
        Serial.print(" 140 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 29) {
        myDFPlayer.play((145 + trackCount));
        Serial.print(" 145 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 30) {
        myDFPlayer.play((150 + trackCount));
        Serial.print(" 150 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 31) {
        myDFPlayer.play((155 + trackCount));
        Serial.print(" 155 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 32) {
        myDFPlayer.play((160 + trackCount));
        Serial.print(" 160 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 33) {
        myDFPlayer.play((165 + trackCount));
        Serial.print(" 165 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 34) {
        myDFPlayer.play((170 + trackCount));
        Serial.print(" 170 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 35) {
        myDFPlayer.play((175 + trackCount));
        Serial.print(" 175 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 36) {
        myDFPlayer.play((180 + trackCount));
        Serial.print(" 180 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 37) {
        myDFPlayer.play((185 + trackCount));
        Serial.print(" 185 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 38) {
        myDFPlayer.play((190 + trackCount));
        Serial.print(" 190 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 39) {
        myDFPlayer.play((195 + trackCount));
        Serial.print(" 195 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 40) {
        myDFPlayer.play((200 + trackCount));
        Serial.print(" 200 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 41) {
        myDFPlayer.play((205 + trackCount));
        Serial.print(" 205 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 42) {
        myDFPlayer.play((210 + trackCount));
        Serial.print(" 210 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 43) {
        myDFPlayer.play((215 + trackCount));
        Serial.print(" 215 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 44) {
        myDFPlayer.play((220 + trackCount));
        Serial.print(" 220 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 45) {
        myDFPlayer.play((225 + trackCount));
        Serial.print(" 225 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 46) {
        myDFPlayer.play((230 + trackCount));
        Serial.print(" 230 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 47) {
        myDFPlayer.play((235 + trackCount));
        Serial.print(" 235 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 48) {
        myDFPlayer.play((240 + trackCount));
        Serial.print(" 240 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 49) {
        myDFPlayer.play((245+ trackCount));
        Serial.print(" 245 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 50) {
        myDFPlayer.play((250 + trackCount));
        Serial.print(" 250 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 51) {
        myDFPlayer.play((255 + trackCount));
        Serial.print(" 255 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 52) {
        myDFPlayer.play((260 + trackCount));
        Serial.print(" 260 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 53) {
        myDFPlayer.play((265 + trackCount));
        Serial.print(" 265 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 54) {
        myDFPlayer.play((270 + trackCount));
        Serial.print(" 270 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 55) {
        myDFPlayer.play((275 + trackCount));
        Serial.print(" 275 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 56) {
        myDFPlayer.play((280 + trackCount));
        Serial.print(" 280 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 57) {
        myDFPlayer.play((285 + trackCount));
        Serial.print(" 285 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 58) {
        myDFPlayer.play((290 + trackCount));
        Serial.print(" 290 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 59) {
        myDFPlayer.play((295 + trackCount));
        Serial.print(" 295 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 60) {
        myDFPlayer.play((300 + trackCount));
        Serial.print(" 300 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 61) {
        myDFPlayer.play((305 + trackCount));
        Serial.print(" 305 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 62) {
        myDFPlayer.play((310 + trackCount));
        Serial.print(" 310 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 63) {
        myDFPlayer.play((315 + trackCount));
        Serial.print(" 315 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 64) {
        myDFPlayer.play((320 + trackCount));
        Serial.print(" 320 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 65) {
        myDFPlayer.play((325 + trackCount));
        Serial.print(" 325 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 66) {
        myDFPlayer.play((330 + trackCount));
        Serial.print(" 330 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 67) {
        myDFPlayer.play((335 + trackCount));
        Serial.print(" 335 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 68) {
        myDFPlayer.play((340 + trackCount));
        Serial.print(" 340 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 69) {
        myDFPlayer.play((345 + trackCount));
        Serial.print(" 345 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 70) {
        myDFPlayer.play((350 + trackCount));
        Serial.print(" 350 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 71) {
        myDFPlayer.play((355 + trackCount));
        Serial.print(" 355 + ");
        Serial.print(trackCount);
      }
      else if (folderCount == 72) {
        myDFPlayer.play((360 + trackCount));
        Serial.print(" 360 + ");
        Serial.print(trackCount);
      }
      delay(50);
    }
    
    void printDetail(uint8_t type, int value){
      switch (type) {
        case TimeOut:
          Serial.println(F("Time Out!"));
          break;
        case WrongStack:
          Serial.println(F("Stack Wrong!"));
          break;
        case DFPlayerCardInserted:
          Serial.println(F("Card Inserted!"));
          break;
        case DFPlayerCardRemoved:
          Serial.println(F("Card Removed!"));
          break;
        case DFPlayerCardOnline:
          Serial.println(F("Card Online!"));
          break;
        case DFPlayerPlayFinished:
          Serial.print(F("Number:"));
          Serial.print(value);
          Serial.println(F(" Play Finished!"));
          break;
        case DFPlayerError:
          Serial.print(F("DFPlayerError:"));
          switch (value) {
            case Busy:
              Serial.println(F("Card not found"));
              break;
            case Sleeping:
              Serial.println(F("Sleeping"));
              break;
            case SerialWrongStack:
              Serial.println(F("Get Wrong Stack"));
              break;
            case CheckSumNotMatch:
              Serial.println(F("Check Sum Not Match"));
              break;
            case FileIndexOut:
              Serial.println(F("File Index Out of Bound"));
              break;
            case FileMismatch:
              Serial.println(F("Cannot Find File"));
              break;
            case Advertise:
              Serial.println(F("In Advertise"));
              break;
            default:
              break;
          }
          break;
        default:
          break;
      }
    }
    
    void serialEvent() {
      while (Serial.available()) {
        // get the new byte:
        char inChar = (char)Serial.read();
        // add it to the inputString:
        inputString += inChar;
        // if the incoming character is a newline, set a flag so the main loop can
        // do something about it:
        if (inChar == '\n') {
          stringComplete = true;
        }
      }
    }
    
    void execute_CMD(byte CMD, byte Par1, byte Par2)
    // Excecute the command and parameters
    {
      // Calculate the checksum (2 bytes)
      word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
      // Build the command line
      byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
                                Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte
                              };
      //Send the command line to the module
      for (byte k = 0; k < 10; k++)
      {
        mySoftwareSerial.write( Command_line[k]);
      }
    }


     

     

    • Like 5
    • Thanks 1
    • Confused 1
  8. Some default state according to what i based it on.  Only just now noticed this utterly disgusting computer seems to have not copy-pasted the rest of neds code.

    enum warningStates_t {IDLE = 0, WARN_MINOR, WARN_GENERAL, WARN_DIRE};
    warningStates_t curState, oldState;

     

  9. 3 hours ago, 00quattro00 said:

    What happens when you put a different body on a chassis? I want to put a land rover series 2 body on a discovery chassis, series 2 is dereg and the discovery is still live would also be shortening the discovery chassis

    I saw someone who did this, but with ford pickups.  It was cert'ed as a body swap.

    /ling

  10. Umm i can't edit the prior post to have

    //high is turning the coil on  for 2ms and low turns it off & makes a spark.
    //wait 10 milliseconds then turn the coil on again, saves much battery.

    I do question why this doesn't compile


     
    
    #define RPM_0        10
    #define RPM_240      240
    #define RPM_500      500
    #define RPM_800      800
    #define RPM_950      950
    #define RPM_1100     1100
    #define RPM_1250     1250
    #define RPM_1400     1400
    #define INCR_250   (RPM_240)
    #define DECR_250   (RPM_240 - 5)
    #define INCR_5     (RPM_240 + 50)
    #define DECR_5     (RPM_500 - 5)
    #define INCR_8     (RPM_500 + 50)
    #define DECR_8     (RPM_950 - 5)
    #define INCR_9     (RPM_800 + 150)
    #define DECR_9     (RPM_1100 - 5)
    #define INCR_11    (RPM_950 + 150)
    #define DECR_11    (RPM_1250 - 5)
    #define INCR_12    (RPM_1100 + 150)
    #define DECR_12    (RPM_1400 - 5)
    #define INCR_14    (RPM_1250 + 150)
    
    enum rpmStates_t {IDLE = RPM_0, RPM_240, RPM_500, RPM_800, RPM_950, RPM_1100, RPM_1250, RPM_1400};
    rpmStates_t curState, oldState;

    Something about expected number before  #define 240 ?
    But the one i based it on does..

    
    #define TEMP_BAND     2
    #define TEMP_MINOR    60
    #define TEMP_GENERAL  75
    #define TEMP_DIRE     90
    #define INCR_MINOR    (TEMP_MINOR + TEMP_BAND)
    #define INCR_GENERAL  (TEMP_GENERAL + TEMP_BAND)
    #define INCR_DIRE     (TEMP_DIRE + TEMP_BAND)
    
    #define DECR_IDLE     (TEMP_MINOR - TEMP_BAND)
    #define DECR_MINOR    (TEMP_GENERAL - TEMP_BAND)
    #define DECR_GENERAL  (TEMP_DIRE - TEMP_BAND)


     

    • Like 1
  11. Putting all the cells in the bike frame would be cool but...
     

    10 hours ago, SOHC said:

    unfortunately no. those little 50cc engines for bikes are not aloud to be used on the road at all.

    Who do i have to tazer dick punch to get this changed?  Pretty sure scratch build mopeds should be a legally allowable thing.

    • Like 5
×
×
  • Create New...