Loading...
  Show Posts
Pages: [1] 2 3 ... 9
1  Using Arduino / Programming Questions / Re: progmem help on: November 16, 2012, 08:47:55 am
I have worked it out now with the code below.
Code:
#include <avr/pgmspace.h>

prog_char hello[3][7] PROGMEM =
{
  "HELLO1",
  "HELLO2",
  "HELLO3"
};

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

void loop()
{
  char str1[16];
 
  sprintf_P(str1, hello[2]);
 
  Serial.print(str1);
 
  delay(5000);
}
2  Using Arduino / Programming Questions / Re: progmem help on: November 16, 2012, 08:39:57 am
I have just noticed AWOL that my strings are not separate lol and thats what i want so i gues my code needs to be something like below
Code:
prog_char hello[] PROGMEM =
{
  "HELLO1",
  "HELLO2",
  "HELLO3"
};

so how would i read the second string?
3  Using Arduino / Programming Questions / Re: progmem help on: November 16, 2012, 08:21:54 am
I don't get any errors apart from the line that says
Code:
sprintf_P(str1, hello[2]);
my full code below.
Code:
#include <avr/pgmspace.h>

prog_char hello[] PROGMEM =
{
  "HELLO1"
  "HELLO2"
  "HELLO3"
};
void setup()
{
 //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial)
  {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
}

void loop()
{
  char str1;
 
  sprintf_P(str1, hello[2]);
 
  Serial.print(str1);
 
  delay(5000);
}

Am wanting to have an array of strings and read them when i want. Just trying to learn about progmem.
4  Using Arduino / Programming Questions / progmem help on: November 16, 2012, 08:12:36 am
Hi all, hope you can help. What is the correct way to read "HELLO2" from the code below?
Code:
prog_char hello[] PROGMEM =
{
  "HELLO1"
  "HELLO2"
  "HELLO3"
};

Many thanks.
5  Using Arduino / Displays / Re: I2C LCD - Setup instructions for 16x2 on: October 29, 2012, 02:09:33 pm
blackscience. No problem, happy to help.
6  Using Arduino / Displays / Re: I2C LCD - Setup instructions for 16x2 on: October 28, 2012, 06:25:27 am
blackscience, have a look at this topic http://arduino.cc/forum/index.php/topic,94633.msg710615.html#msg710615%20%28http://arduino.cc/forum/index.php/topic,94633.msg710615.html#msg710615. May help you.
7  Using Arduino / Programming Questions / Re: int and unsigned int on: October 09, 2012, 01:58:41 am
Ok thanks Nick. No it wont. What am doing is getting the data over the OBD port on the vehicle and storing the value in a unsigned int as a DEC number between 0 and 8000 and that works great. So what am trying to do here is take that number and turn on some LED's (depending on what the RPM value is) over the SPI port to a 16bit shift register. Sorry if i have not really explaind myself properly here but i will try and explain as best as i can again.

I will have 16 LED's in a row (1 = LED on and 0 = LED off).
For example my RPM value is 5000. Out of 16 LED's i want to turn on 5 LED's on the left and 5 LED's on the right. So the efect i want on my LED's is below
1111100000011111 <- (binary number)/(63519, dec number) 5000RPM
1111110000111111 <- (binary number)/(64575, dec number) 6000RPM, turn on 6 LED's either side
1111111001111111 <- (binary number)/(65151, dec number) 7000RPM, turn on 7 LED's either side

So i hope you can see what effect am trying to create (LED's light up from the left and right at the same time and meet up in the middle at max RPM).

Thats why am using binary (bitshift)
Code:
Display_RPM = ~((1 << (16 - temp))-1) | ((1 << temp)-1);
to create that efect everytime i read a new RPM value then send the effect out to the shift register. I was going to use a lookup table for patterns but i was told a better way would be to use bitshift and if only 1 line of code.

Hope that makes sense, if not then slap me with a fish lol. I will post my project on here when i think it's ready to share.
8  Using Arduino / Programming Questions / Re: int and unsigned int on: October 08, 2012, 03:47:42 am
That's how I want to show the rpm value on a row of LEDs as part of a digital dash for my track car. A good example would be the f1 steering wheel then you might get the idea. I think the original question has been missed here now.
9  Using Arduino / Programming Questions / Re: int and unsigned int on: October 08, 2012, 02:18:55 am
Ok thanks AWOL but can you understand what am trying to achieve here. I will try and get a shift register this week and then see how wrong my code is when it don't display the results i was hoping for because my code is bound to be wrong.
10  Using Arduino / Programming Questions / Re: int and unsigned int on: October 08, 2012, 02:07:42 am
Quote
Why are you looking at it in binary in the first place?

Who wants to see RPM in binary?

Because i don't have a shift register at the moment so i was using the serial monitor to to show me what the output / effect would look like if i did send the information to a shift register. 1 = LED on and 0 = LED off and i will have 16 LED's.

Quote
[And how did you manage to get negative RPM?
It's not clear to me what the "correct" method of displaying a negative number in binary would be, or whether it would be worth the special case code to limit the binary display to 16bits for an "int."

It's not a negative number because my variable is a unsigned int / word and they don't hold negative numbers according to the reference section. If i set my variable Display_RPM to an int and display the created value in the serial monitor, then i get a negative number. If i set my variable to unsigned int/word then i get a positive number and that is what i want.

Code:
#define pin A0 //Pot connected for testing.

byte temp;
unsigned int Display_RPM;
unsigned int result;

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

void loop()
{
  result = map(analogRead(pin), 0, 1024, 0, 8000); //Maps the pot value to simulate RPM value.

  temp = result/1000;
  Display_RPM = ~((1 << (16 - temp))-1) | ((1 << temp)-1);
  Serial.println(Display_RPM, BIN);
  Serial.println(Display_RPM);
  delay(900);
}

1 = LED on, 0 + LED off
below is what i think i would see on a 16bit shift register when i buy one.

1000rpm = 1000000000000001
2000rpm = 1100000000000011
3000rpm = 1110000000000111
4000rpm = 1111000000001111
5000rpm = 1111100000011111
6000rpm = 1111110000111111
7000rpm = 1111111001111111
8000rpm = 1111111111111111

Does that explain everything now.
11  Using Arduino / Programming Questions / Re: int and unsigned int on: October 07, 2012, 03:39:41 pm
The unsigned int variable or delcared as a word is what i was wanting to create and works great in my main code. But because at first i had the variable "Display_RPM" delcared as just an int and seeing 32bits in the serial monitor just didn't add up. The documentation for a int value in the reference section says it's meant to be 16bits not 32bits that am seeing in the serial monitor. So because am a beginner at C++ and Arduino this was very confusing for me and thought my understanding was wrong, hence why i thought it was a silly question in the first place.

How do you report a bug?
12  Using Arduino / Programming Questions / Re: int and unsigned int on: October 07, 2012, 03:10:39 pm
Sorry Nick. Here is what i see in the serial monitor below.

unsignd int value
1111111001111111
int value
11111111111111111111111001111111
13  Using Arduino / Programming Questions / Re: int and unsigned int on: October 07, 2012, 02:22:09 pm
Here is my test code that shows in the serial monitor what am talking about, displays a int value that has 32bits and an unsigned int that has 16bits.

Code:
byte temp;
unsigned int result = 7000;
unsigned int Display_RPM_A;
int Display_RPM_B;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
  temp = result/1000;
  Display_RPM_A = ~((1 << (16 - temp))-1) | ((1 << temp)-1);
  
  temp = result/1000;
  Display_RPM_B = ~((1 << (16 - temp))-1) | ((1 << temp)-1);
  
  Serial.println("unsigned int value");
  Serial.println(Display_RPM_A, BIN);
  
  Serial.println("int value");
  Serial.println(Display_RPM_B, BIN);
}

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

(Changed code above because the wrong lable was being printed).
14  Using Arduino / Programming Questions / Re: int and unsigned int on: October 07, 2012, 05:09:04 am
Thank you, that explains a few different websites. So am i right in thinking in Arduino a int is 32bits long and an unsigned int is 16bits long? Well from what i can see in the serial monitor it is. Sorry for the so called dumb questions but i have never used any programing till a few months ago and am tring to learn myself Arduino and actual C++.
15  Using Arduino / Programming Questions / Re: int and unsigned int on: October 07, 2012, 04:55:48 am
Arduino reference says int 2bytes but if i look here http://www.tutorialspoint.com/cplusplus/cpp_data_types.htm an int is 4bytes.
Pages: [1] 2 3 ... 9