Show Posts
Pages: 1 ... 34 35 [36] 37 38 ... 66
526  Using Arduino / Displays / Re: Can the Sainsmart 3.2" TFT be turned on & off? on: December 24, 2012, 09:48:49 pm
Hello and welcome smiley

I modified the UTFT library like this. It is the turn on/off sequences, as described in the SSD1289 datasheet. It works, but does not control the backlight. Better than nothing smiley

Code:
void UTFT::lcdOff()
{
cbi( P_CS, B_CS );
switch ( display_model )
{
case PCF8833:
LCD_Write_COM( 0x28 );
break;

//I added this ------------------------
case SSD1289:
//turn OFF
LCD_Write_COM_DATA( 0x07,0x0000 );
LCD_Write_COM_DATA( 0x00,0x0000 );
LCD_Write_COM_DATA( 0x10,0x0001 );

//only standby mode ON: no visible difference?
//LCD_Write_COM_DATA( 0x10, 0x0001 );
break;
//-------------------------------------
}
sbi(P_CS, B_CS);
}

void UTFT::lcdOn()
{
cbi( P_CS, B_CS );
switch ( display_model )
{
case PCF8833:
LCD_Write_COM( 0x29 );
break;

//I added this ------------------------
case SSD1289:
//turn ON
LCD_Write_COM_DATA( 0x07, 0x0021 );
LCD_Write_COM_DATA( 0x00, 0x0001 );
LCD_Write_COM_DATA( 0x07, 0x0023 );
LCD_Write_COM_DATA( 0x10, 0x0000 );
delay(30);
LCD_Write_COM_DATA( 0x07, 0x0033 );
LCD_Write_COM_DATA( 0x11, 0x60B0 );
LCD_Write_COM_DATA( 0x02, 0x0600 );
LCD_Write_COM( 0x22 );

//only standby mode OFF: no visible difference?
//LCD_Write_COM_DATA( 0x10, 0x0000 );
break;
//-------------------------------------
}
sbi( P_CS, B_CS );
}

Look here: http://arduino.cc/forum/index.php?topic=125856.0 . If you do the hardware modification described in this topic, please report if it worked for you smiley

PS, I have exactly the same display, do you also have about 1 to 2mm slack at the left side, that you have to press to get uniform lighting?
527  Using Arduino / Programming Questions / Re: Need Help Arduino Array on: December 24, 2012, 05:46:17 am
wow guix,
i must say i never seen any programming that use array like yours. could you teach me more about your style.

It's not "my" style smiley

Here are 2 useful links, read them and you will learn more than if I try to explain to you with my bad english..

http://www.cplusplus.com/doc/tutorial/arrays/
http://www.cplusplus.com/doc/tutorial/structures/
528  Using Arduino / Programming Questions / Re: Need Help Arduino Array on: December 24, 2012, 05:20:37 am
Quote
or atleast tell me that i have the basic idea in my head?

Yes, I suggest a few changes (so you can learn even more smiley)

Use a global constant for the size of the array, this way if you need to modify that number, you only modify it at one place
Use a struct to organize all the data of a LED and use only one array.

Code:
const uint8_t MAX_LEDS = 3;

struct LED
{
  uint8_t pin;
  bool state;
  uint32_t time;
};

LED leds[ MAX_LEDS ] =
{
  { 2, LOW, 103 },
  { 3, LOW, 293 },
  { 4, LOW, 487 },
};

...

for ( uint8_t i = 0; i < MAX_LEDS; i++ )
{
  if( currentMillis - previousMillis > leds[i].time)
  {
    leds[i].state = !leds[i].state;
    digitalWrite( leds[i].pin,  leds[i].state );
  }
}
529  Using Arduino / Programming Questions / Re: Need Help Arduino Array on: December 24, 2012, 04:28:48 am
Hello smiley

Arrays are really useful, I can't imagine a program without them..or a very small and simple program maybe!

Using a for loop to set or get all values in an array or multidimensional array can be done with 2 or very few lines of code, while without arrays, the same result would be done by manually writing maybe hundreds of lines.

They are also good to keep things organizated, used in combination with enums or structs, or pointers to arrays.. Really they are like the best feature of almost any programming languages.

As for an example, I don't know...the most basic program I write would use arrays anyway smiley
530  Using Arduino / Project Guidance / Re: A toggle switch to call a function and then turn off the Arduino on: December 22, 2012, 08:36:24 pm
Yes that's why I posted here and not in Programming smiley

What external hardware would be required?
531  Using Arduino / Project Guidance / A toggle switch to call a function and then turn off the Arduino on: December 22, 2012, 08:06:54 pm
Hello smiley

I would like to know if it's possible that if I press a toggle switch (to turn on/off the Arduino power), to first call a function in the sketch, such as "SaveBeforeShutDown()", and only turn off the Arduino one second after to let the function enough time to finish, or better if possible, turn off immediately when the function has exited.

It must be possible, but how?
532  Using Arduino / Programming Questions / Re: trouble with simple IF...ELSE on: December 22, 2012, 03:04:37 pm
Make it static, or global. Actually it is erased when the function is exited, and recreated each time the function is called.
Code:
void BlinkLED13()
{
  // blinks LED 13
  static int pinstate;
533  Using Arduino / Programming Questions / Re: Receive binary data into a variable on: December 21, 2012, 05:19:36 am
But a bit will be read as a byte by Serial.read()..Correct?
534  Using Arduino / Programming Questions / Re: Receive binary data into a variable on: December 21, 2012, 05:11:24 am
Ok then you have to wait receiving 8 bytes, that you then convert in a single byte smiley

Something like this (maybe):
Code:
void loop()
{
  if ( Serial.available() == 8 )
  {
    byte bytes[8];
    for ( uint8_t i = 0; i < 8; i++ )
      bytes[i] = Serial.read();

    byte result = 0;
    for ( uint8_t i = 0; i < 8; i++ )
      result += bytes[7-i] << i;

    byte ID = (result & 0xF0) >> 4;
    if ( ID == ARDUINO_ID )
    {
      byte ASCII =  result & 0x0F;
      DisplayTo7Seg( ASCII );
    }
  }
}

So if the bytes sent by your device are for example: 1,1,0,0,0,1,0,1 , the ID will be 1100, and the ASCII value will be 101.

Note, I'm beginner too so there may be a better way, or maybe my code won't even work smiley
535  Using Arduino / Programming Questions / Re: Receive binary data into a variable on: December 21, 2012, 04:29:42 am
What is sending 8 bits to the Arduino? You with the Serial monitor, or a sensor/device?

I need the arduino to listen for it's own ID

So you have 10 Arduinos, each with it's own ID?
536  Using Arduino / Programming Questions / Re: Receive binary data into a variable on: December 21, 2012, 03:36:58 am
Hello and welcome smiley

You could wait for 8 separate bits, or you could send a single byte that you then parse in your sketch smiley

Example:
Code:
byte binary_data = 0b11000101;

byte ID_variable = (binary_data & 0xF0) >> 4; //will be equal to 0b1100
byte another_var =  binary_data & 0x0F;       //will be equal to 0b0101
537  Using Arduino / Programming Questions / Re: convert char array to byte array on: December 21, 2012, 02:03:37 am
Hello, you can also use the strtol function, example:
http://codepad.org/i8QgK2Hf
538  Using Arduino / Programming Questions / Re: How do I get the 3d byte of a word? on: December 21, 2012, 12:17:36 am
Hello, something like that:
Code:
b3 | (b2 << 8) | (b1 << 16)
539  Using Arduino / Programming Questions / Re: Get data from web and display them on 7-segment display on: December 20, 2012, 06:41:30 pm
Hello and welcome smiley

You have to post your code so we can look at it smiley

I think you need to store the last result in EEPROM but, only do it when absolutely needed because EEPROM have a short life time. Do not write to EEPROM every loop() ! And then, when Arduiono is reset, load the last value from EEPROM.
540  Using Arduino / Programming Questions / Re: POOR MAN'S RTC on: December 20, 2012, 05:53:21 pm
And a DS3231 for less than 6$

http://www.ebay.com/itm/RTCpro-DS3231-Precision-Clock-Module-With-Temperature-Arduino-For-AVR-PIC-51-ARM-/150956915543?pt=LH_DefaultDomain_0&hash=item2325bbbb57
Pages: 1 ... 34 35 [36] 37 38 ... 66