Show Posts
Pages: 1 2 [3] 4 5 ... 14
31  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 12:47:29 pm
Thank you all so much, it works.

Now i have just one question:

I also want to display text of the value from an analog pin. With this code:
Code:
char analogval = analogRead(lightpin);
uoled.Text(0,0, 2, 150, analogval,1);

But the Text function needs a char* i think, because i get this error when compiling:
Code:
Invalid conversion from 'char' to 'char*'
.
32  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 12:41:49 pm
It compiles, fingers crossed!
33  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 11:44:47 am
Another good example of why you should always explain what you are trying to accomplish instead of what you want to do.
Yes, i've learned that now. Here goes:

The documentation also says 'Definition at line 114 of file uOLED.cpp.'

Here's the part of uOLED.cpp and further:
Code:
void uOLED::Rectangle (char x1, char y1, char x2, char y2, int color, char filled)
{
  PenSize(filled);

  write(0x72);
  write(x1);
  write(y1);
  write(x2);
  write(y2);
  write(color >> 8);
  write(color & 0xFF);
  res=RBack();
}

The (write) function is just
Code:
    pSerial->write(pData);

This is what the LCD datasheet has to say about color:
Code:
colour:   2 bytes (16 bits) define the background colour in RGB format:
R4R3R2R1R0G5G4G3G2G1G0B4B3B2B1B0 where:
msb : R4R3R2R1R0G5G4G3
lsb :    G2G1G0B4B3B2B1B0
By the way, i have an uLCD-144 (SGC)

Hope this informs you
34  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 11:30:02 am
The 'Rectangle' function in a uOLED library, this is what the manual says:
Code:
void uOLED::Rectangle ( char x1,
char y1,
char x2,
char y2,
int color,
char filled
)
Draw a rectangle.

Draw a rectangle with upper-left corner at x1,y1 and the bottom-right corner at x2,y2. Lines will have 16bit color. filled=true -> fill the rectangle with the color given.
Note that the sides of the rectangle can not be diagonal on the screen.
What i'm trying to generate, is the HEX color int.
35  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 11:22:19 am
Now i'm trying to use the 'hex' in a function which needs an integer, and it gives me the following error:
Code:
invalid conversion from 'char*' to 'int'
.
36  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 11:17:44 am
Wow, thank you Tom. You just made my life so much easier!
37  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 11:00:56 am
Trying some stuff. Now i got this:
Code:
byte R, G, B;
int R12 = 255;
int G12 = 0;
int B12 = 255;
R = R12;
G = G12;
B = B12;
long RGB = (R << 16) | (G << 8) | B;
    Serial.println(RGB, HEX);
But it just returns FF in staead of FF00FF
38  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 10:53:47 am
I'm thinking this could be a lot simpler, but i don't really know how. I have 1 decimal 0-255 integer. I need to convert it to HEX, and repeat it 3 times in one string that's 6 characters long, so even if the original integer is 0, it eventually needs to be 000000. And if the original integer is 10, it needs to be 0A0A0A.
39  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 10:33:41 am
Oh yeah, i forgot. Above it is
Code:
byte R, G, B;
40  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 10:12:55 am
Why use an int variable when you want a byte variable?
Because this is just some test code, in the eventual code, another part generates an int from 0-255.

Quote
I don't understand the second line.
Me neither, but i couldn't find any information on how to do it else.
41  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 10:08:01 am
I already tried it like this:
Code:
int R12 = 255;
R = (R12, BYTE);

But it won't work...
42  Using Arduino / Programming Questions / Re: RGB to HEX on: August 05, 2012, 09:56:20 am
So you want to convert three numbers to one number?

The best way is to use shifts:
Code:
byte R, G, B;
long RGB = (R << 16) | (G << 8) | B;
If you then want to print the number as hexadecimal:
Code:
Serial.println(RGB, HEX);

Remember that decimal, hexadecimal, octal, binary, characters, etc are just ways of displaying the number. Internally, everything is stored as binary.

I tried everything, but how do i convert the 0-255 dec to a byte?
43  Using Arduino / Programming Questions / Re: 5-way switch programming on: August 04, 2012, 04:19:39 pm
Thanks again John, really appreciate it.
44  Using Arduino / Programming Questions / Re: RGB to HEX on: August 04, 2012, 04:18:07 pm
I understand, thanks. Now how do i convert it to an integer?
45  Using Arduino / Programming Questions / [SOLVED] 5-way switch programming on: August 04, 2012, 02:06:56 pm
Thank you, it works.
Pages: 1 2 [3] 4 5 ... 14