Show Posts
Pages: 1 ... 389 390 [391] 392 393 ... 516
5851  Using Arduino / Programming Questions / How safe this programming practice is? on: May 21, 2011, 01:36:54 pm
I have a struct where a few members are unions I call four_bytes:

Code:
union four_bytes
{
int i;
long l;
float f;
byte b;
char c;
};

struct phi_prompt_struct
{
  four_bytes step;
}

I do this to save memory. Sometimes I need floating numbers so I can store it in step.f. Other times I need integer I will do step.i.
Now, to further save space, I want to save four bytes of data into step. How safe is it to do this practice? 100% safe, or depends?

Code:
*(&step.c+0)=ch0; // OR step.c=ch0;
*(&step.c+1)=ch1;
*(&step.c+2)=ch2;
*(&step.c+3)=ch3;
5852  Community / Exhibition / Gallery / Re: Phi_prompt new release teaser - scrolling list items on: May 21, 2011, 01:19:01 pm
Here is a new draft for display options, any more input?

Display options:

Bit 0 – Arrow or dot. The first column of the list is a dot if it is not highlighted or an arrow if it is highlighted. This is very useful if you display more than one item on your list.
Bit 1 – index list 1 thru 0. This draws an index (1234567890) at column and row, encoded in step.i as column*100+row. The highlighted item is indicated on the index as a special character, right now as “^”. In later version of the library, I might make this customizable.
Bit 2 – an index current/total, such as 5/12. This is drawn at column and row, encoded in step.i as column*100+row. The highlighted item is the number before the slash while the total list item is after the slash.
Bit 3 – auto scroll. This enables auto scrolling of list items that are too long to fit within given display width. Not enabling this option results in truncated display of first few characters that will fit within given display width.

Bit 4 – flashing cursor. This turns on a flashing black box enabled by the display. The cursor is at the beginning of the list item highlighted.
Bit 5 – Center choice. The highlighted item will always be centered in the display when possible (odd number of rows to display and plenty of items before and after the highlighted item). The list will scroll automatically to center the choice you might make.
Bit 6 – Scrolling bar. This displays a scrolling bar on the right side of the list. It looks like a DOS editor and is only useful for multi-line of list items. Make sure that you don't have anything immediately to the right of the list or run out of screen space.
Bit 7 – Reserved. This is reserved for future options and should not be used.
5853  Community / Exhibition / Gallery / Re: Phi_prompt new release teaser - scrolling list items on: May 21, 2011, 12:25:55 pm
Now the right video is attached  smiley-sweat

Right, if I lose the dot I can save a character, but now I have scrolling items I can be less strict on space saving now. Doing flashing cursor is certainly easy but I don't know if GLCD has corresponding function when porting to GLCD. I'll give it a shot at flashing cursor though.
5854  Topics / Education and Teaching / Arduino workshop featured at American Association of Physics Teachers conference on: May 21, 2011, 12:48:31 am
http://www.aapt.org/Conferences/sm2011/workshops.cfm

Search (ctrl+F) for session W20. I'll be there to gauge interest in using arduino for physics teaching.
5855  Topics / Education and Teaching / Re: Program 4 sending commands to COM port on: May 21, 2011, 12:42:28 am
A very standard solution is a firmata. Just read about it on arduino.cc or try an example in arduino ide under examples->firmata. You will need processing to run the pc side software.
5856  Using Arduino / Displays / Re: Display for Direct Sunlight on: May 21, 2011, 12:38:41 am
I bought a character LCD from adafruit a while back, the one with white text against blue background. It's impossible to read without back light but under direct sun it's quite readable.
5857  Community / Exhibition / Gallery / Remote control light show! on: May 20, 2011, 11:08:06 pm
I used an IR remote control I bought to create a light show, totally customizable via the remote.







Code:
/*
Arduino infrared remote control light show

Programmed by Dr. John Liu
Revision: 05/20/2011
Free software for educational and personal uses.
No warrantee!
Commercial use without authorization is prohibited.
Find details of my libraries and hardware or contact Dr. Liu at
http://liudr.wordpress.com/
All rights reserved.

Dependent library:
Ken Shirriff's IRremote library
*/

#include <IRremote.h>

#define myClockPin 10  // The clock pin for the shift registers
#define myLatchPin 11  // The latch pin for the shift registers
#define myDataPin 12  // The data pin for the shift registers

int RECV_PIN = 9;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  pinMode(myDataPin,OUTPUT);
  pinMode(myClockPin,OUTPUT);
  pinMode(myLatchPin,OUTPUT);
  irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
  static byte last; // Stores last decoded result in case the remote control sends repeat code.
  static byte current; // Stores a number to be displayed on the leds. This has nothing to do with IR remotes.
  static boolean forward_dir=true, run=false, mirror=false;
  if (irrecv.decode(&results))
  {
    byte ret=find_key(results.value);
    if (ret==254) last=254; // flush last key with invalid if invalid input is detected in case invalid remote sends out 0xffffffff that triggers repeat.
    else // For valid for this remote
    {
      if ((ret==255)&&(last!=254)) ret=last; // Make sure last key was not invalid before doing repeat.
      else last=ret;
      
      switch (ret)
      {
        case '0':
        current=0;
        break;
        
        case '1':
        current=1;
        break;
        
        case '2':
        current=B11;
        break;
        
        case '3':
        current=B111;
        break;
        
        case '4':
        current=B1111;
        break;
        
        case '5':
        current=B11111;
        break;
        
        case '6':
        current=B111111;
        break;
        
        case '7':
        current=B1111111;
        break;
        
        case '8':
        current=B11111111;
        break;
        
        case 'C':
        current++;
        break;
        
        case 'c':
        current--;
        break;
        
        case 'R':
        current=~current;
        break;
        
        case 'P':
        if (current==0) current=255;
        else current=0;
        run=false;
        mirror=false;
        break;
        
        case 'v':
        current=(current>>1)|(B10000000*(bitRead(current,0)));
        break;
        
        case 'V':
        current=(current<<1)|(bitRead(current,7));
        break;
        
        case 'L':
        forward_dir=!forward_dir;
        break;
        
        case 'T':
        run=!run;
        break;

        case 'A':
        mirror=!mirror;
        break;
      }
        
      updateLed(current);
    }
    irrecv.resume(); // Receive the next value
  }
  
  if (run)
  {
    if (forward_dir)
    {
      current=(current<<1)|(bitRead(current,7));
    }
    else
    {
      current=(current>>1)|(B10000000*(bitRead(current,0)));
    }
      updateLed(current);
  }
  
  if (mirror)
  {
    current=~current;
    updateLed(current);
  }
  
  delay(100);
}

char find_key(unsigned long code)
{
  const char codes[]="ML1470ST258-Iv369APVUCcR";
  byte col, row, temp;
  if (code==0xffffffff) return (255); // Repeat
  else if ((code&0xffff0000)==0x40bf0000)
  {
    temp=lowByte((code-0x40BF00FF)/0x7f8)<<3;
    for (byte i=0;i<8;i++)
    {
      bitWrite(col,i,bitRead(temp,7-i));
    }
    row=col>>2;
    col=col&B11;
    return (codes[col*6+row]);
  }
  else return 254; // Invalid code. Not from this remote control.
}

void updateLed(unsigned char first8)  // Updates LED status using shift registers.
{
  digitalWrite(myLatchPin, LOW);  // Disable update to the output buffers.
  shiftOut(myDataPin, myClockPin, LSBFIRST, first8);//MSBFIRST when flat LSBFIRST when standing.
  digitalWrite(myLatchPin, HIGH);  // Enable update to the output buffers.
}

5858  Community / Exhibition / Gallery / Re: Modular Stackable Microcontroller System (lots of pics) on: May 20, 2011, 11:02:19 pm
Agreed. I do have scrolling menu/list with many rendering options smiley

You can run two 40X2 displays or 2 20X4 displays with one arduino, just use different EN lines and make two lcd objects.

RE: number, nice and big! Here's my version, not only numbers are large, so are all other characters including letters and symbols smiley

http://liudr.wordpress.com/libraries/phi_super_font/



Again same set of lcd functions are required.
5859  Community / Exhibition / Gallery / Re: Phi_prompt new release teaser - scrolling list items on: May 20, 2011, 10:39:13 pm
OK, one new list render version is out:
(Initially attached the wrong video)

5860  Community / Exhibition / Gallery / Re: Modular Stackable Microcontroller System (lots of pics) on: May 20, 2011, 10:30:20 pm
Yes, size issues. How about scrolling text area instead of relying on the size of the screen?

5861  Community / Exhibition / Gallery / Re: Modular Stackable Microcontroller System (lots of pics) on: May 20, 2011, 09:54:28 pm
I was just about to ask what you have for that display. I'll take some time to read it. I got an abstract deadline next week so hopefully will get to it very soon.

Just IMHO that if you base on this display you may have trouble secure enough stock compared with HD44780 displays.

I believe all I used were:
clear()
setCursor(int, int)
print(char *)
write(char)
and
createChar(int, char*) only for scroll bars that mowcius asked smiley A less decent version would be using a black box and white box for less accurate scroll bar. I really don't want to let the scroll bar go, so DOS.

Everything was based on the above.
5862  Community / Exhibition / Gallery / Re: Modular Stackable Microcontroller System (lots of pics) on: May 20, 2011, 09:10:56 pm
I wonder if you could make up the last two buttons "logically" with a "chording" of some combination of other buttons...

100% doable. Just define virtual buttons (combos) as null buttons and modify the wait_on_escape function so it recognizes combos as another button press.

This is a great suggestion. I will implement a combo button so you can just say:

phi_buttons btn_6(btn_combo, LOW);
btn_6.setCombo(btn_1,btn_2);

So btn_6 becomes a virtual button that gets pressed when both are pressed down and released when one of them is released. I just need time to make it happen more elegantly, like I just mocked up.
5863  Community / Exhibition / Gallery / Re: Modular Stackable Microcontroller System (lots of pics) on: May 20, 2011, 09:03:36 pm
You can always define any key as null button so they don't do anything or use any pins.

Say if you think you can get away with up/down/left/right, then define enter and escape as null buttons and you don't have to rewrite anything:

#define btn_null 255

phi_buttons btn_1(btn_u, LOW);
phi_buttons btn_2(btn_d, LOW);
phi_buttons btn_3(btn_l, LOW);
phi_buttons btn_4(btn_r, LOW);
phi_buttons btn_5(btn_null, LOW);
phi_buttons btn_6(btn_null, LOW);

This way your up/down function covers all change of values, left/right cover going from one number entry to previous/next one or jog in a text entry. Right/left arrow also dubs as enter/escape but you can certainly change its meaning. 100% useable. I was able to use all my stuff on even one button, an up auto button, and a right actual button. All you need it patience.


5864  Community / Exhibition / Gallery / Re: Modular Stackable Microcontroller System (lots of pics) on: May 20, 2011, 07:25:45 pm
Very nice work.

Implementing this on the 24x8 LCD's I have would be very cool.

This is where I got a couple from. They accept TTL level Serial or RS232 Level Serial, @ 19200 baud.
http://cgi.ebay.com/Intel-8032-Single-Board-Controller-Serial-24-x-8-LCD-/120726684894?pt=LH_DefaultDomain_0&hash=item1c1bdf04de

I have about 6 of them. They were $15 at the time when got them.

My library is built entirely over the LiquidCrystal library so if LiquidCrystal runs on this display, there is no reason the library won't run. Its layer is higher than hardware display driver library so I hope to port it to more displays with minimal work. What library do you use on your display?
5865  Community / Exhibition / Gallery / Re: Phi_prompt new release teaser - scrolling list items on: May 20, 2011, 06:01:45 pm
One more thing: do you want a list that wraps around itself so the highlighted item is always displayed in the middle:

Code:
10.
1.
2.High lighted item
3.
4.

Or do you want a list that starts from this:

Code:
1. High lighted item
2.
3.

Then it ends with this:

Code:
8.
9.
10. High lighted item
Pages: 1 ... 389 390 [391] 392 393 ... 516