Loading...
  Show Posts
Pages: 1 2 [3] 4 5 ... 9
31  Using Arduino / Programming Questions / Re: Bitshift help. on: September 30, 2012, 03:38:43 pm
I have just tested that and yes it does work, great. What is the -1 doing in this if you don't mind me asking (i have not used these functions before so this is new to me)? If am going to use it i need to know what it is doing lol but thanks a bunch to WizenedEE and Grumpy_Mike.
32  Using Arduino / Programming Questions / Re: Bitshift help. on: September 30, 2012, 03:19:26 pm
Yes Grumpy_Mike but for example if result was 4 then i need that code to create 11110000.
33  Using Arduino / Programming Questions / Re: Bitshift help. on: September 30, 2012, 02:20:34 pm
Thank you, you have been most helpfull and i understand now.
Quote
I'm almost certain there is a better way to do this than using a loop or a lookup table though.
If anyone knows then that would be great.
34  Using Arduino / Programming Questions / Re: Bitshift help. on: September 30, 2012, 01:18:03 pm
Thank you, could please explain what this is doing b = b | (1 << i); because i cant get my head around it and if i had a value of 6 i would get 111111 but do i need to add 2 0's at the end to make up the full 8 bits like 11111100? Also is this a good way to do what am trying to do or would using a array like this be a better way ?
Code:
byte ArrayRPM[8] =
{
  B00000000,
  B10000000,
  B11000000,
  B11100000,
  B11110000,
  B11111000,
  B11111100,
  B11111110,
  B11111111,
};
35  Using Arduino / Programming Questions / Bitshift help. on: September 30, 2012, 12:01:19 pm
Hello all,

Code:
//Main.
void loop()
{
  byte b = 0;
  unsigned long temp = 0;
  unsigned long result = 0;
  char str[32];
  
  Ignition_State_Check();
  
  get_PID(ERPM, &result, str);
  temp = result/1000;
  for(byte i = 0; i < temp; i++)
  {
    b = 1 << 1 | 1;
  }
  Serial.print(b, BIN);
  delay(1000);
}

Am a bit stuck for ideas and not sure if am trying to do this correctly. I have a value in unsigned long result then that gets divided by 1000 to give me either a 0 or a 1 or a 2 or a 3 or a 4 or a 5 or a 6 or a 7 or a 8 depending whats in unsigned long temp. I then am trying to use a for loop to give me for example in byte b 00111111. This will then be used to light up 6 out of 8 LED's but i ony get is 00000010. Can anyone tell me what am doing wrong?

Thanks.
36  Using Arduino / Programming Questions / Re: Control Two LED's with one button on: September 27, 2012, 03:51:12 pm
Have a look at the statechangedetection example that comes with the Arduino software. With a few little changes this can be done very easily.
37  Using Arduino / Programming Questions / Re: STRING To HEX Converter on: September 19, 2012, 02:45:38 pm
Quote
No, strtoul() doesn't put anything into any sort of string. It parses an unsigned long integer from a string.

I know it doen't. I was just saying thats how i use it and that it's easy to use.
38  Using Arduino / Programming Questions / Re: STRING To HEX Converter on: September 19, 2012, 01:13:07 pm
I use strtoul(). It puts my ASCII sting into a unsigned long HEX string that i can use for anything and is only one line of code.
39  Using Arduino / LEDs and Multiplexing / Re: LED driver ic. What devices do you all use? on: September 19, 2012, 12:52:47 am
Thanks I will have a look. SMD soldering is my job so that's not a problem lol. The chip I was looking at can also be used as i/o expander but is optimised for LEDs with brightness control.
40  Using Arduino / LEDs and Multiplexing / Re: LED driver ic. What devices do you all use? on: September 18, 2012, 03:50:23 pm
Thanks. Av been looking at this http://uk.farnell.com/on-semiconductor/cat9532wi-t1/led-driver-16bit-program-24soic/dp/1656134 that looks interesting and a ok price.
41  Using Arduino / LEDs and Multiplexing / LED driver ic. What devices do you all use? on: September 18, 2012, 02:28:49 pm
Hello forum,

Am just interested about what 16 bit LED drivers you all use? Do you prefer i2c or SPI? I have never used 12c or SPI before and am trying to get a bit of background on the most commonly used LED drivers around here. If i choose one that is used alot around here i may have a better chance on getting it to work.

Many thanks.
42  Using Arduino / LEDs and Multiplexing / Re: RPM LEDs code help. on: September 18, 2012, 02:17:21 pm
Thinking about using one of these http://uk.farnell.com/on-semiconductor/cat9532wi-t1/led-driver-16bit-program-24soic/dp/1656134
43  Using Arduino / LEDs and Multiplexing / Re: RPM LEDs code help. on: September 17, 2012, 03:28:50 pm
Food for thought is good, thank you. I do plan on using a LCD aswell to display engine load etc. I can get any info i want from the car now and display it in the serial monitor but i will be having lots of display items so am not sure how to code a routine to update all the displays with no visable delays. So far in the end i want 2 4 digit seven segment displays (1 for speed and 1 for voltage or something) a row of 8 LED's for RPM + 1 LED for the shit indicator and a LCD for as i said above) It's gonna be a lot of pins needed so i would like to use the i2c bus for all may display items.
44  Using Arduino / LEDs and Multiplexing / Re: RPM LEDs code help. on: September 17, 2012, 02:55:16 pm
Also am wanting to have a shift LED that will flash when the RPM gets to a pre set value via a rotary switch / hex switch.
45  Using Arduino / LEDs and Multiplexing / RPM LEDs code help. on: September 17, 2012, 02:48:37 pm
Hello all. I have a sketch that reads a cars ECU via OBD that all works great but now its time to move on and actually displaying some info. Am looking at using the i2c bus to control LEDs and seven segments but to start with i just want to use 8 LEDs to show RPM (1 LED = 1000RPM).

Code:
#define ERPM    0x0C //Engine RPM.

//Main.
void loop()
{
  unsigned long result = 0;
   
  get_PID(ERPM, &result);
  if(result <= 999)
  {
   // B00000000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
  }
  else if(result >= 1000 && result <= 1999)
  {
    //B10000000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
  }
  else if(result >= 2000 && result <= 2999)
  {
    //B11000000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
  }
  else if(result >= 3000 && result <= 3999)
  {
    //B11100000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
  }
  else if(result >= 4000 && result <= 4999)
  {
    //B11110000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
  }
  else if(result >= 5000 && result <= 5999)
  {
    //B11111000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
  }
  else if(result >= 6000 && result <= 6999)
  {
    //B11111100 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
  }
  else if(result >= 7000 && result <= 7999)
  {
    //B11111110 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
  }
  else if(result >= 8000 && result <= 8999)
  {
    //B11111111 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
  }
}

A little info about the above, unsigned long result = 0; is a variable that will contain anything from 0 to 9000 and get_PID(ERPM, &result); is the command that gets the info from the car that works fine.

As you can see from the above that i want to turn on some LEDs over i2c (to the LED driver) to show the rpm. Am i better using some kind of for loop and place the binary valuse in a const struct or array or PROGMEN?

Any ideas or examples would be great. In the end i will be adding more i2c ic's to display speed on a seven segment.
Pages: 1 2 [3] 4 5 ... 9