Show Posts
Pages: 1 ... 128 129 [130] 131 132 ... 361
1936  Using Arduino / Programming Questions / Re: How to make arduino do 2 things at once on: July 26, 2013, 05:35:58 pm
Be sure to go to Nick's link. It is the best starting tutorial I know on doing more than one thing at a time. You will know why as well as what and how.

UGH....one of those moments.  My newbiness couldn't overcome currentMillis = 999 and previousMillis = 0xFFFFFFFF.  But I see it now.  My apologies.  Thank you for the patience.

Yes, the bits. Takes time to learn but well worth it.

HEX is base 16. 1 hex digit can be decimal 0 to 15 as hex 0 to 9 or A to F where A=10, F=15.
But the bits, there are 4 and with practice it's easier to read hex than binary.

bits high to low = 8 4 2 1 so binary 1111 = 1x8 + 1x4 + 1x2 + 1x1, binary 0011 = 1x2 + 1x1.

0 0000  0 --- 0x0 is no bits set
1 0001  1
2 0010  2
3 0011  3
4 0100  4
5 0101  5
6 0110  6
7 0111  7
8 1000  8
9 1001  9
A 1010 10
B 1011 11
C 1100 12
D 1101 13
E 1110 14
F 1111 15 --- 0xF is all bits set

If you run Windows, open the calculator and under View change it to Scientific.
You now can switch between HEX, DEC, OCT and BIN. In HEX the A to F keys are active.

Every text character is 8-bit ASCII, even the unprintable ones. They all take 2 hex digits.

Once you know bits you can start to get into bit shifting and bit logic and do bit masking. With those you can change or read the pins on a PORT all at the same time in less than 1 millionth of a second. To get closer to the metal you need solder.

Just take care when shifting bits right (high to low). If the high bit (bit 7 of a byte or short, bit 15 of an unsigned int or int) is 1 then as the bits shift right, the new high bit will be 1. That 'fill' doesn't happen with left-shift, just right-shift.
1937  Using Arduino / Programming Questions / Re: Check if some of the buttons was pressed while executing a "for" loop. HELP! on: July 26, 2013, 02:08:10 pm
looks like you are calling rgb();
from within rgb()


There is the major problem. rgb() runs rgb() with no escape until the return addresses stack down to overwrite the heap (your variables) after a very long time.

The delay just slows it all down and keeps your code from noticing a pressed button.

Learning BlinkWithoutDelay from your IDE examples (can be reduced to 12 lines of code not counting the comments) is the first step in learning real-time code with Arduino. It's funny how hard less than 20 lines of code can be to follow.




Unfortunately if i dont write that down the rgb() will run only once after i press the button, i need it to keep running indefinitely until the button is pressed. The funny thing is that nothing solved it until now, may i give up? That can't be a impossible thing to achieve right?

It is very possible to run rgb() over and over but that leaves you with the next big problem which is button (control) response. Do you want to have to wait for rgb() to finish and have the button pressed for the tiny fraction of a second before rgb() runs again? Or do you want to be able to press a button and get 'instant gratification' ?
1938  Using Arduino / Programming Questions / Re: How to make arduino do 2 things at once on: July 26, 2013, 02:03:25 pm
Please run the sketch I put up in reply #6 and you will see what happens at rollover.
Change the numbers, ask about HEX if you need as that is just an easy way to read bits.

Computer binary maths are not the same as paper and pencil decimal maths.

 
1939  Using Arduino / Programming Questions / Re: Check if some of the buttons was pressed while executing a "for" loop. HELP! on: July 26, 2013, 12:46:25 pm
looks like you are calling rgb();
from within rgb()


There is the major problem. rgb() runs rgb() with no escape until the return addresses stack down to overwrite the heap (your variables) after a very long time.

The delay just slows it all down and keeps your code from noticing a pressed button.

Learning BlinkWithoutDelay from your IDE examples (can be reduced to 12 lines of code not counting the comments) is the first step in learning real-time code with Arduino. It's funny how hard less than 20 lines of code can be to follow.



1940  Using Arduino / Programming Questions / Re: How to make arduino do 2 things at once on: July 26, 2013, 12:18:33 pm
If you want to get the whole 49 days, 17 hours, 2 minutes and 47.296 seconds possible then unlike the official example in the IDE you have to use unsigned long for -all- of the time variables. The ones to 'fix' (add unsigned in front of long) in the example are
Code:
long previousMillis = 0;        // will store last time LED was updated

long interval = 1000;           // interval at which to blink (milliseconds)

Morris Dovey put up a timer library that uses 64-bit unsigned long long variables good for well over 500,000 years using micros() instead of millis(). I don't remember where to find it though.

Here is a sketch that uses unsigned math and shows the results in DEC, HEX and BIN.
Code:
unsigned long a, b, c;

void setup() {
  Serial.begin( 9600 );
  a = 0xffffff00UL;
  b = 0x10UL;
  Serial.println( "\n unsigned math\n" );
  Serial.print( "a = ");
  Serial.print( a, DEC );
  Serial.print( " = 0x");
  Serial.print( a, HEX );
  Serial.print( " = 0b");
  Serial.println( a, BIN );
  Serial.print( "b = ");
  Serial.print( b, DEC );
  Serial.print( " = 0x");
  Serial.print( b, HEX );
  Serial.print( " = 0b");
  Serial.println( b, BIN );
  if ( b >= a ) Serial.println( "b >= a" );
  else          Serial.println( "a > b" );
  c = a - b;
  Serial.print( "a - b = ");
  Serial.print( c, DEC );
  Serial.print( " = 0x");
  Serial.print( c, HEX );
  Serial.print( " = 0b");
  Serial.println( c, BIN );
  c = b - a;
  Serial.print( "b - a = ");
  Serial.print( c, DEC );
  Serial.print( " = 0x");
  Serial.print( c, HEX );
  Serial.print( " = 0b");
  Serial.println( c, BIN );
  c = b - (b + 1);
  Serial.print( "b - (b + 1) = ");
  Serial.print( c, DEC );
  Serial.print( " = 0x");
  Serial.print( c, HEX );
  Serial.print( " = 0b");
  Serial.println( c, BIN );
 
  while( 1 );
}

void loop() {};
1941  Using Arduino / Programming Questions / Re: function; vs function(); on: July 26, 2013, 09:23:51 am
Pointers to functions can be great.
Instead of a function with a switch-case to many functions by number that you HAVE to go through to access those functions by number, a table of pointers to the same functions can be directly accessed by index (number) faster than using the switch-case by any code that can scope that table. That's a mouthful saying how the pointer table is faster and more flexible once set up. The part I haven't tried yet is using function pointers in PROGMEM.

************* This post started out as an attempt to show how to make
Code:
int (*(*fun_one)(char *,double))[9][20];
more clear using typedef.
But between either videocard or java problems (when I'm done here, I'm going godzilla and rebuild on my java install) causing my IDE to act like it's on bad acid I've had to cut it short. My aggro-level is kind of high right now *****************

BTW, properly used, typedef (like enum) is really beautiful for code clarity and brevity.

this works in Arduino IDE 1.03 but note the comments about function address
Code:
int func( char *C )
{
  return ( int ) C[ 0 ];
}

int (*foo)(char *) = &func; // this time I use the address-of &

typedef int ( *fun_one )( char * );
fun_one myFun = func; // this time I don't use the address-of &
fun_one fun[9][20];

void setup( void )
{
  Serial.begin( 9600 );
  Serial.println( "test" );
 
  char X[4] = "123";
  Serial.println( foo( X )); // they both seem to work
  Serial.println( myFun( X ));

// the -expletive-deleted- says ambiguous whenever I try an print the function addresses
 
  while( 1 );
}

void loop( void )
{
}

Useful tutorial links:
http://www.cprogramming.com/tutorial/typedef.html
http://www.cprogramming.com/tutorial/function-pointers.html

1942  Community / Bar Sport / Re: battery density on: July 25, 2013, 05:10:07 am
If you can get a wide enough temperature differential, Peltier wafers will give you volts. Just how many you'd need depends on the situation.

In one of the Roja's video Denise shows that squirrel cage fans work very well as windmills. Why build what you can find in scrapyards? Almost every big central air unit has a major size blower. Similarly most appliance AC motors can be modified to generate power. I expect that you might bet breezes towards evening?

Put up 3 different ways to generate. One may carry the bulk of the load with another boosting the current.

1943  Community / Bar Sport / Re: battery density on: July 24, 2013, 12:22:27 pm
20 AH would be a small car battery.
1944  Community / Bar Sport / Re: battery density on: July 24, 2013, 10:21:39 am
How thick is the wire and contact that goes to a 12V 20A car fuse? How thick is the fuse?

1945  Community / Bar Sport / Re: Critical thinking and programming. on: July 24, 2013, 01:44:49 am
Sometimes my English just isn't up to a short explanation of logic so if I'm feeling up to it I throw out code or pseudocode, but I am sparing with the comments. Hey, early on I did learn a lot, including tracing code, while fixing/modifying OPC (Other People's Code) in line-number interpreter BASIC that had NO comments. For me, the code IS the comments.

1946  Community / Bar Sport / Re: battery density on: July 24, 2013, 01:37:39 am
With the heat you get, maybe a Stirling engine and generator.

Put these into the youtube search box:
---------------------------------------------------------------------------
GIANT DEATH RAY Daniel's DIY $25 giant parabolic
Parabolic Mirror from a Trash Can Lid
Solar Power Parabolic Trough Mirror Kit Evacuated Solar Tube
Fresnel Lens and a Stirling Engine for FREE ENERGY Solar
SOLAR PANEL DIY MAKE YOUR OWN SOLAR
less than $1 a watt DIY MAKE YOUR OWN SOLAR PANEL
---------------------------------------------------------------------------

When I see the ones with Denise, I don't seem to be able to remember what was said.
1947  Community / Bar Sport / Re: Fake Arduino. on: July 24, 2013, 12:06:35 am
Heck, you can make/distribute my '1284 boards. Be awesome for robots.
Provides more IO, dual hardware serial, more memory. Not marked Arduino anything.
http://www.crossroadsfencing.com/BobuinoRev17/


Do you sell assembled boards or is that cost-prohibitive here?

1948  Using Arduino / Programming Questions / Re: How to start a loop with a manual switch on: July 24, 2013, 12:02:51 am
It would matter if you intend to use the button once in loop().

It's also nice to know a bit about debouncing switches.

Explosives.... this old amateur pyrotechnician would want interlocks no matter how often (pretty much always) he's used green fuse (sometimes with cigarette or other slow-burn on the fuse) for ignition. Anything big, I'd want more than one switch and a cutoff.

Please note that if ===anything=== goes astray and ===anyone=== even gets close to hurt, the lawyers will eat your home-built ignition control and you alive unless you've gotten the thing certified which won't be cheap.

1949  Community / Bar Sport / Re: Hello world... on: July 23, 2013, 11:12:22 pm
Do you want to say anything about your Arduino-related (electronics & code ferinstance) strengths and weaknesses?

Bookmark these below. Each has useful info/links.
================================================
http://arduino.cc/en/Reference/HomePage
http://www.nongnu.org/avr-libc/user-manual/modules.html
http://arduino.cc/en/Tutorial/HomePage
http://arduino.cc/en/Main/Products

1950  Community / Bar Sport / Re: Fake Arduino. on: July 23, 2013, 11:05:34 pm
@RoboticsGuy

Look into compatibles as well as clones. As long as it doesn't have the Arduino name (you can use the schematic, not the name, go figure) and you don't call it Arduino then I think you're outside of violation ( ANYBODY? ).

A lot of compatibles have extra features. I for one wouldn't mind seeing an UNO with a ZIF socket. Rugged design makes UNO compatibles that can take 12V (or is it 24V) on the I/O pins. PJRC makes the Teensy's that have native USB AVR's able to be HID's without modifying the hardware. 

Maybe spread your net a bit and look into AVR boards as compatibles?


Pages: 1 ... 128 129 [130] 131 132 ... 361