No response from automotive light module on UNO


hi everybody,

this first time posting here, hope placed correct.
for school project working on porsche being built racing spec. accomodate easy use of flash pass , patterns in hazard lights, thought nice use arduino of this.

the arduino should able switch low , high beams on, flash high beams several times when specific button pressed, activate turn signals , switch rainlight on of vehicle.

for this, wanted use arduino uno, combined mosfet shield sparkfun (6 predefined mosfet outputs). show activated, wanted use 16x2 lcd had @ home, isn't implemented in code yet. switches connected gnd internal pull-up resistors enabled.

this first part of code, things have until now. when wanted test code, halfway through programming functions, got no response @ when pushing buttons.
what should happening when lowbeamswitch pushed, low beams should turn on, when highbeamswitch button pressed, high beams should turn on , when flashtopassswitch button pressed, high beams (and if not active already, low beams well) should flash 3 times. in order not let interfere regular highbeam , lowbeam functions, set flags couldn't interfere.

i ran on code several times now, still unable find error in code. guess in switch debounce part, me looks alright.

i appreciate help!

yours sincerely,

joël
code: [select]
// programming pins 0 , 1 should disconnected

// pin definitions switches
const byte lowbeamswitch = 0;
const byte highbeamswitch = 1;
const byte flashtopassswitch = 2;


// pin definitions mosfet's
const byte lowbeam = 3;
const byte highbeam = 5;


// constants


const int shortflash = 125; // indicates time [ms] needed short flash, used in hazard mode
const int longflash = 250;  // indicates time [ms] needed long flash, used in hazard mode , turn signals
const byte flashtopassflashes = 3; // indicates how many flashes done when flash pass button pressed.

const int debouncedelay = 50; // debounce time when switch activated

// variables debouncing
byte lowbeamswitchstate;  // current state of switch
byte highbeamswitchstate;
byte flashtopassswitchstate;


byte lastlowbeamswitchstate = 1;  // previous state of switch (high/low)
byte lasthighbeamswitchstate = 1;
byte lastflashtopassswitchstate = 1;


unsigned long lastdebouncetimelowbeam = 0;  //reference measuring debounce, initialised @ 0
unsigned long lastdebouncetimehighbeam = 0;
unsigned long lastdebouncetimeflashtopass = 0;


// variables millis delay
unsigned long previousmillislowbeam = 0;  // store last time mosfet updated
unsigned long previousmillishighbeam = 0;
unsigned long previousmillisflashtopass = 0;


// variables toggling outputs
byte lowbeamstate = 0;
byte highbeamstate = 0;


byte flashtopassflag = low; // when flag toggled, flash pass loop active , high beam loop interrupted
byte lowbeamflag = low; // when flag toggled, lowbeam loop active , lowbeam isn't included in flash pass
int flashtopasscounter = 0;

// include lcd library code

#include <liquidcrystal.h>


// initialize library numbers of interface pins
liquidcrystal lcd(14, 15, 16, 17, 18, 19);

void setup() {
  // initialise switches inputs internal pull-up resistors enabled
  pinmode (lowbeamswitch, input_pullup);
  pinmode (highbeamswitch, input_pullup);
  pinmode (flashtopassswitch, input_pullup);
 

  // initialise mosfet's outputs
  pinmode (lowbeam, output);
  pinmode (highbeam, output);
  
}

void loop() {
  // put main code here, run repeatedly:

  lowbeamloop();
  flashtopassloop();
  highbeamloop();
}

//-----------------------------------------------------------------------------------------

void lowbeamloop() {
  if (digitalread(lowbeamswitch) != lastlowbeamswitchstate) { //  if switch changed, due noise of switching
    lastdebouncetimelowbeam = millis();  // reset debouncing timer
  }
  if ((millis() - lastdebouncetimelowbeam) > debouncedelay) {

    //  the debounce time has passed, valid switching
    if (digitalread(lowbeamswitch) != lowbeamswitchstate) {
      lowbeamswitchstate = digitalread(lowbeamswitch);// reset debouncing timer

      if (lowbeamswitchstate != lastlowbeamswitchstate) { // if switch has been switched
        lowbeamstate = !lowbeamstate; // toggle low beam
        digitalwrite(lowbeam, lowbeamstate);  // output mosfet
        lowbeamflag = !lowbeamflag; // flip lowbeam flag
      }
    }
  }
  lastlowbeamswitchstate = digitalread(lowbeamswitch);  // set last value detect changes next time
}

//-----------------------------------------------------------------------------------------

void flashtopassloop() {
  if (flashtopassflag == low) {
    if (digitalread(flashtopassswitch) != lastflashtopassswitchstate) { //  if switch changed, due noise of switching
      lastdebouncetimeflashtopass = millis();  // reset debouncing timer
    }
    if ((millis() - lastdebouncetimeflashtopass) > debouncedelay) {

      //  the debounce time has passed, valid switching
      if (digitalread(flashtopassswitch) != flashtopassswitchstate) {
        flashtopassswitchstate = digitalread(flashtopassswitch);// reset debouncing timer
        if (flashtopassswitchstate != lastflashtopassswitchstate) { // if switch has been switched
          flashtopassflag = !flashtopassflag; // flip flash pass flag
        }
      }
    }
    lastflashtopassswitchstate = digitalread(flashtopassswitch);  // set last value detect changes next time
  }
  else {
    if ((millis() - previousmillisflashtopass) >= longflash) {
      previousmillisflashtopass = millis();

      if (flashtopasscounter >= 0 && flashtopasscounter <= ((flashtopassflashes * 2) - 1)) {
        flashtopasscounter++; // increment flash pass counter
        highbeamstate = !highbeamstate; // toggle high beam
        digitalwrite(highbeam, highbeamstate);  // output mosfet

        if (lowbeamflag == low) {
          lowbeamstate = !lowbeamstate; // toggle low beam if not activated regular
          digitalwrite(lowbeam, lowbeamstate);  // output mosfet
        }
      }
      else {
        flashtopassflag = low;  //reset flash pass flag
      }
    }
  }
}

//-----------------------------------------------------------------------------------------

void highbeamloop() {
  if (flashtopassflag == low) {
    if (digitalread(highbeamswitch) != lasthighbeamswitchstate) { //  if switch changed, due noise of switching
      lastdebouncetimehighbeam = millis();  // reset debouncing timer
    }
    if ((millis() - lastdebouncetimehighbeam) > debouncedelay) {

      //  the debounce time has passed, valid switching
      if (digitalread(highbeamswitch) != highbeamswitchstate) {
        highbeamswitchstate = digitalread(highbeamswitch);// reset debouncing timer

        if (highbeamswitchstate != lasthighbeamswitchstate) { // if switch has been switched
          highbeamstate = !highbeamstate; // toggle high beam
          digitalwrite(highbeam, highbeamstate);  // output mosfet
        }
      }
    }
  }
}

//-----------------------------------------------------------------------------------------




code: [select]
// programming pins 0 , 1 should disconnectedwhy use them in first place ?

i going suggest put serial.print()s in code @ strategic points if use pins 0 , 1 not possible.


Arduino Forum > Using Arduino > Programming Questions > No response from automotive light module on UNO


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts