Show Posts
Pages: [1] 2 3 ... 10
1  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Enhanced LiquidCrystal on: February 20, 2010, 11:36:39 am
I'm probably overthinking this.  I had thought that the display had something like a 200Hz refresh cycle, but that appears to be the refresh of one row, not the whole display.  The datasheet I'm looking at shows a 64hz frame rate.  at 64 Hz, I only need to get the bar graph into the LCD in 15 ms more or less, which clearly works without the RW.  I don't really want to use the RW, because I want to use the pin for something else smiley
2  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Enhanced LiquidCrystal on: February 19, 2010, 10:51:13 am
Great work.

I've been wondering about the RW pin.  

I have a project in development that needs a very fast bar graph.  I was going to use the programmable characters to make the last segment variable length to get a one dot wide bar resolution.

There are two, possibly academic questions:
  • Is "faster than the eye can see" really true for something like a bar graph?
  • Is there any way to, and do you get any advantage out of, trying to sync the value update (which is related to analog sampling in my case) to the refresh cycling of the LCD?

I was thinking of an experiment that involves getting the bar graph working, and then using something like an adjustable sine wave synthed signal to drive it.  Walk the frequency up until you can't really get the bar graph to follow the signal.  Try that with and without the RW.

I'm in the middle of building a shield for this project and can't try this experiment right now, but I'm planning to.  Do you have an old version of the code around I could try?
3  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: switch...case on: February 27, 2010, 12:04:54 pm
The thing to remember about a switch statement is that once the execution matches the value after "case", it starts executing statements until it executes a break.  The braces aren't needed.  If you executed:
Code:
switch (i) {
case 1: j=1;
case 2: j=2;
case 3; j=3;
default: j=4;
}
then j will always be 4.

a switch like:
Code:
switch (i) {
case 1: { a=1; b=2;} break;
case 2: { a=-1; b=-2;} break;
}
is exactly the same as
Code:
switch (i) {
case 1:  a=1; b=2; break;
case 2:  a=-1;
         b=-2;
         break;
}
or
Code:
switch (i) {
case 1: { a=1; b=2; break; }
case 2: { a=-1; b=-2; break; }
}
or even
Code:
switch (i) {
case 1: { a=1;} b=2; break;
case 2: { a=-1;} b=-2; break;
}

4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Parse string and replace character on: May 19, 2010, 10:43:00 am
we need more information to help you better.  Is the pattern for the input and output very consistent (that is, string lengths are always the same, and the positions of the changed characters is consistent, or if not, how dos it vary?

In general, I would:
use a loop to copy the string from one place to another.  If the prolog was constant length, you can index the initial string with an offset to skip it.  While you copy you can inspect the character being copied for the '-' and store a '#' instead.  It may be that the space between the xxx and the HTTP is always there, and you can use that to terminate the loop.

so, if indeed, the "GET /?" is always exactly that, then the loop looks something like:

i=0;
while (originalString[i+6] <> ' ') {
  if (originalString[i+6] = "-") finalString="#';
  else finalString = originalString[i+6];
  i++;
}
finalString=0; 

warning, i typed this fast, did not try it, and often commit some syntax error, but you get the idea
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Advice on reading a nonlinear analog input on: May 21, 2010, 08:47:36 am
"Piecewise linear fit" is very often how you do it.

however, depending on how much of your code memory space you are using, i'd be inclined to make a lookup table in program space and use that to map from the sensor to the temp readings.

6  Forum 2005-2010 (read only) / Syntax & Programs / Re: 5 minute on-off cycles for loop? HELP on: May 19, 2010, 02:12:15 pm
In this case, you don't need the "loop variable", x.  

for (x=0;x<18;x++) {
  your code goes here and doesn't use x
}

x is just counting up how many times the morse code sequence is repeated.

You also need the 10 minute delay after the for loop.

10 minutes is 10 x 60 x 1000 = 600,000 milliseconds.    Look at delay() but be aware of what the size of the parameter to delay is, and compare to 600,000 (that is a hint to learn about how many bytes variables take up in memory, and what the largest number you can store in those variables could be, and what you do when you need a bigger number);
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: 74HC595 lag using pushbutton as inputs on: April 15, 2010, 09:13:05 pm
How are the buttons wired?

One possible reason is that there is no pullup on the inputs and they are floating when not pressed.

Conventionally, you wire one side of the button to ground, the other side to the input, and then digitalWrite(<pin>, HIGH) to enable the built in pullup.  Note that the button will read LOW when depressed if you do that.
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: array of variable names, is it possible on: April 15, 2010, 09:28:18 pm
Your code works, but it's inefficient.  

What you are doing is creating a series of two byte variables in memory, and loading them with a constant number (50, 51, 52).

Then you create an array of addresses, each entry of which takes two bytes, to hold the address of the two byte variables you created first.

Your code then steps through the array, extracts the address of the two byte variable, goes there, and gets the constant, which is the pin number.  

pceric gave you the right answer.  Just make an array of pin numbers.  Then your loop just steps through the array picking up the pin number directly.

Your way takes twice as much memory, and takes some percentage, maybe 30% longer to execute, and you get nothing for it.

Learning to use pointers is valuable, but don't use pointers when the variable the pointer points to is always constant and all you ever do is run through the list in order extracting the value.
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Simple increment problem on: April 05, 2010, 09:05:24 am
Another way to do this is to have an array with the rollover days

byte maxDays[]={0,31,27,31,...};
 (the zero is because arrays start at index zero)
then you can have
if (days++ > (int)maxDays[month] {
  days =1;
  if (month++ > 12) {
     month=1;
     year++
  }
}
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Map() Function - am i missing something? on: March 02, 2010, 01:31:00 pm
In general, analog thingies have "offset" and "scale" issues, and very often, non linearities.  They are analog, not digital.

It may well be that your touch screen can't output zero for the corner, or maybe it could, but only if your finger was infinitely small.

So, generally, y=mx+b is your friend if it's linear.
The "+b" is the offset.  "m" is the scale.  Map is doing that for you.

Your problem can be that 0 is NOT what the input for left (or bottom) is: it could be something bigger.

1023 may NOT be what right or top is: it could be smaller.

So, what you want to do is measure without map or constrain.  Find out what the actual min and max are.  Put those in the appropriate places in map.  If this is a one-off, you can build these calibration values into the code.  If this is to be replicated, you need a calibration routine, and you store the values in EEPROM
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: asm macro error on: February 27, 2010, 02:51:56 pm
Learn more assembler.

Push a register into the stack (push)

set it to 63 (ldi)

decrement and jump until zero (dec and rjmp)

pop the stack back into the register (pop)

I think the problem has been diagnosed correctly: it's a compiler bug due to the size of the code the asm inserts.

Having 64 NOPs inline is a silly way to delay, so use this bug to learn more assembler.
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need help with "for" on: February 25, 2010, 10:08:57 pm
Some basics on FOR

You have those three expressions.  You usually see them as
for (i=0;i<something;i++)

The first expression is executed before the loop starts.
The second is executed at the top of the loop to see if it should loop again
The third is executed at the bottom of the loop.

IT DOES NOT MATTER WHAT THE EXPRESSIONS ARE or what they do.  They can be anything you want.  There isn't anything that says they have to involve an integer.  There isn't any thing that says they have to use the same variable.  There isn't anything that says the third expression has to add 1.  It can be anything.  The middle one has to resolve to an expression that has a true/false answer, but since true = non-zero, it really can be just about anything.

All the matters is that it's going to execute the first one before, the second one at the top of the loop to decide if it will go around again, and the bottom one at the end of the loop.

this works
for (i=-234.5;j<200;a=b*c) {
... }

now, what is inside the loop had better modify j in some way that eventually, j becomes less than 200 or the loop won't end (although you can break out of a loop other ways).

Because it doesn't matter, there is NOTHING special about the "loop variable".  You can modify it with impunity inside the loop.  All that matters is that, eventually, the middle expression becomes true.

Now, there might be clearer ways of writing code that has
for (i=-234.5;j<200;a=b*c) {

BUT IT'S PERFECTLY GOOD C CODE
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: parsing integers through serial on: February 03, 2010, 05:50:38 pm
It's a good idea in general to learn how to do these things, because it teaches you how the systems really work.  What the previous posters are explaining is that an integer in the range you are trying to send can be broken into bytes by "shift and mask" operations.  The "mask" is an AND operator ("&"), the shift is the ">>" and "<<" operators.  You mask off the bottom byte, then you shift and mask the top byte to encode, then you shift and combine, using the OR ("|") operator to combine them on the Arduino.  If you convert numbers to binary, and use the basic AND/OR operations, you can work out how this does what you want.  Do watch out about signed vs unsigned quantities here: you want unsigned bytes.

Having said that, you are probably better actually sending the 4 character string.  It's easier, it's clearer, and it's easier to debug.  It certainly is less efficient, but in this case, what is more important?
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: Please help with RFID program on: January 22, 2010, 05:05:11 pm
Move the definitions of GoodTag and BadTag above the loop definitions.

I personally don't know how to use something defined as
long long tags[], but I gave you the basic idea of how you use bits instead of strings.  I used tags[3][n] for a two dimensional array.  It's a bit inefficient to use double indexed arrays, because the compiler usually needs to use multiply.  Standard space/time tradeoff.

The idea I gave you was to convert strings of hex characters into hex nibbles, and shift/add them to create words (unsigned ints).

comparing is easy, you just compare the integers directly (although you need a loop if you do it with two dimensional arrays like I suggested).
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: Please help with RFID program on: January 22, 2010, 01:48:44 pm
Put the constructor (SoftwareSerial RFID = SoftwareSerial(rxPin,txPin) in the outer global variable area (before void setup()).  Do the same with the LCD constructor.
Pages: [1] 2 3 ... 10