Go Down

Topic: Bitshift help. (Read 1 time) previous topic - next topic

Pavilion1984

Ok cheers. Is bit set good to use here or keep using the << stuff? Am just trying to work out a routine now.

Pavilion1984

I have managed to create the following test sketch to simulate my real program and try to implement the gear shit indicator led flash. The timings have been slowed down for easier reading in the serial monitor.
Code: [Select]
byte temp;
byte Display_RPM;
byte ShiftIndicator = 5;
unsigned long result = 6902;

long previousMillis = 0;

byte flash(long Interval)
{
  long currentMillis = millis();
  if(currentMillis - previousMillis > Interval)
  {
    previousMillis = currentMillis;
    return 1;
  }
  else
  {
    return 0;
  }
}

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  temp = result/1000;
  Display_RPM = ~((1 << (8 - temp)) -1);
  if(temp >= ShiftIndicator && flash(1000) == 1)
  {
    bitSet(Display_RPM, 0);
    Serial.println(Display_RPM, BIN);
  }
  else
  {
    Serial.println(Display_RPM, BIN);
  }
  delay(900);
}

Is there a better way todo this or is this ok? The useful thing is that i can use the flash routine for other things too.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy