Pages: 1 [2]   Go Down
Author Topic: Bitshift help.  (Read 1230 times)
0 Members and 1 Guest are viewing this topic.
Scunthorpe, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Scunthorpe, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Pages: 1 [2]   Go Up
Jump to: