Skip to main content

Site Navigation

Your Account

Choose Language

Anything programming related to the Hexbright

34 Questions View all

Change blink to dazzle in factory mode

I am trying to change the blink to dazzle in the factory mode for an police officer. I have pieced it together but I can't get the dazzle to the brightest setting. Can anyone point me in the right direction?

Answer this question I have this problem too

Is this a good question?

Score 0
Add a comment

2 Answers

You probably need to add "digitalWriteFast(DPIN_DRV_MODE, HIGH)" to your code.

Was this answer helpful?

Score 0
Add a comment

Save the following Piece of code as a new file called factory_Dazzle.ino then open in Arduino IDE and upload to hex

/*

Modified firmware for HexBright FLEX

Changed the Blink Mode to the DAZZLE Mode

v1.0 Mar 9 2014

By Erll

*/

#include <math.h>

#include <Wire.h>

// Settings

#define OVERTEMP 340

// Pin assignments

#define DPIN_RLED_SW 2

#define DPIN_GLED 5

#define DPIN_PWR 8

#define DPIN_DRV_MODE 9

#define DPIN_DRV_EN 10

#define APIN_TEMP 0

#define APIN_CHARGE 3

// Modes

#define MODE_OFF 0

#define MODE_LOW 1

#define MODE_MED 2

#define MODE_HIGH 3

#define MODE_DAZZLING 4

#define MODE_DAZZLING_PREVIEW 5

// State

byte mode = 0;

unsigned long btnTime = 0;

boolean btnDown = false;

void setup()

{

// We just powered on! That means either we got plugged

// into USB, or the user is pressing the power button.

pinMode(DPIN_PWR, INPUT);

digitalWrite(DPIN_PWR, LOW);

// Initialize GPIO

pinMode(DPIN_RLED_SW, INPUT);

pinMode(DPIN_GLED, OUTPUT);

pinMode(DPIN_DRV_MODE, OUTPUT);

pinMode(DPIN_DRV_EN, OUTPUT);

digitalWrite(DPIN_DRV_MODE, LOW);

digitalWrite(DPIN_DRV_EN, LOW);

// Initialize serial busses

Serial.begin(9600);

Wire.begin();

btnTime = millis();

btnDown = digitalRead(DPIN_RLED_SW);

mode = MODE_OFF;

Serial.println("Powered up!");

}

void loop()

{

static unsigned long lastTime, lastTempTime, lastAccTime;

static float lastKnobAngle, knob;

static byte blink;

unsigned long time = millis();

// Check the state of the charge controller

int chargeState = analogRead(APIN_CHARGE);

if (chargeState < 128) // Low - charging

{

digitalWrite(DPIN_GLED, (time&0x0100)?LOW:HIGH);

}

else if (chargeState > 768) // High - charged

{

digitalWrite(DPIN_GLED, HIGH);

}

else // Hi-Z - shutdown

{

digitalWrite(DPIN_GLED, LOW);

}

// Check the temperature sensor

if (time-lastTempTime > 1000)

{

lastTempTime = time;

int temperature = analogRead(APIN_TEMP);

Serial.print("Temp: ");

Serial.println(temperature);

if (temperature > OVERTEMP && mode != MODE_OFF)

{

Serial.println("Overheating!");

for (int i = 0; i < 6; i++)

{

digitalWrite(DPIN_DRV_MODE, LOW);

delay(100);

digitalWrite(DPIN_DRV_MODE, HIGH);

delay(100);

}

digitalWrite(DPIN_DRV_MODE, LOW);

mode = MODE_LOW;

}

}

// Do whatever this mode does

switch (mode)

{

case MODE_DAZZLING:

case MODE_DAZZLING_PREVIEW:

if (time-lastTime < 10) break;

lastTime = time;

digitalWrite(DPIN_DRV_EN, random(4)<1);

break;

}

// Periodically pull down the button's pin, since

// in certain hardware revisions it can float.

pinMode(DPIN_RLED_SW, OUTPUT);

pinMode(DPIN_RLED_SW, INPUT);

// Check for mode changes

byte newMode = mode;

byte newBtnDown = digitalRead(DPIN_RLED_SW);

switch (mode)

{

case MODE_OFF:

if (btnDown && !newBtnDown && (time-btnTime)>20)

newMode = MODE_LOW;

if (btnDown && newBtnDown && (time-btnTime)>500)

newMode = MODE_DAZZLING_PREVIEW;

break;

case MODE_LOW:

if (btnDown && !newBtnDown && (time-btnTime)>50)

newMode = MODE_MED;

break;

case MODE_MED:

if (btnDown && !newBtnDown && (time-btnTime)>50)

newMode = MODE_HIGH;

break;

case MODE_HIGH:

if (btnDown && !newBtnDown && (time-btnTime)>50)

newMode = MODE_OFF;

break;

case MODE_DAZZLING_PREVIEW:

// This mode exists just to ignore this button release.

if (btnDown && !newBtnDown)

newMode = MODE_DAZZLING;

break;

case MODE_DAZZLING:

if (btnDown && !newBtnDown && (time-btnTime)>50)

newMode = MODE_OFF;

break;

}

// Do the mode transitions

if (newMode != mode)

{

switch (newMode)

{

case MODE_OFF:

Serial.println("Mode = off");

pinMode(DPIN_PWR, OUTPUT);

digitalWrite(DPIN_PWR, LOW);

digitalWrite(DPIN_DRV_MODE, LOW);

digitalWrite(DPIN_DRV_EN, LOW);

break;

case MODE_LOW:

Serial.println("Mode = low");

pinMode(DPIN_PWR, OUTPUT);

digitalWrite(DPIN_PWR, HIGH);

digitalWrite(DPIN_DRV_MODE, LOW);

analogWrite(DPIN_DRV_EN, 64);

break;

case MODE_MED:

Serial.println("Mode = medium");

pinMode(DPIN_PWR, OUTPUT);

digitalWrite(DPIN_PWR, HIGH);

digitalWrite(DPIN_DRV_MODE, LOW);

analogWrite(DPIN_DRV_EN, 255);

break;

case MODE_HIGH:

Serial.println("Mode = high");

pinMode(DPIN_PWR, OUTPUT);

digitalWrite(DPIN_PWR, HIGH);

digitalWrite(DPIN_DRV_MODE, HIGH);

analogWrite(DPIN_DRV_EN, 255);

break;

case MODE_DAZZLING:

case MODE_DAZZLING_PREVIEW:

Serial.println("Mode = dazzling");

pinMode(DPIN_PWR, OUTPUT);

digitalWrite(DPIN_PWR, HIGH);

digitalWrite(DPIN_DRV_MODE, HIGH);

break;

}

mode = newMode;

}

// Remember button state so we can detect transitions

if (newBtnDown != btnDown)

{

btnTime = time;

btnDown = newBtnDown;

delay(50);

}

}

Was this answer helpful?

Score 0
Add a comment

Add your answer

Kyle Moulton will be eternally grateful.
View Statistics:

Past 24 Hours: 0

Past 7 Days: 0

Past 30 Days: 0

All Time: 370