Show Posts
Pages: 1 ... 27 28 [29] 30 31 ... 86
421  Using Arduino / Programming Questions / Re: uno to pro mini tx rx on: October 14, 2013, 01:31:46 am
You probably need to press the reset button on the mini pro to get the download started.

Start the compile/download. When the Rx light starts to flash, press the reset button. This makes the bootloader start.
422  Using Arduino / Storage / Re: How would I use this SD card breakout/adapter? on: October 13, 2013, 04:59:06 am
423  Using Arduino / Project Guidance / Re: Counting Number of times a button is pushed on: October 12, 2013, 10:56:49 pm
Yes there is. Lots of examples if you google for it.
424  Using Arduino / Programming Questions / Re: Serial only works after upload on: October 12, 2013, 10:55:38 pm
OP said it was an Uno in his post.
425  Using Arduino / Programming Questions / Re: Serial only works after upload on: October 12, 2013, 10:49:59 pm
There could be a difference between the sketch not running and just not getting serial output. Try flashing a led on and off every second and see if that is going even when you don't get serial output.
426  Using Arduino / Project Guidance / Re: digital pot on: October 12, 2013, 05:04:29 pm
firstly you need to keep track of the number you have between 0-255, and every time that you detect the button you increment the variable and then send that to the pot. The serial comms are SPI, which is the same as you would use for a 595 shift register, of which there are LOTS of examples usually associated with setting LED patterns. The application may be different, but the technique is exactly the same. The circuits will also be identical (clock, data and enable/latch digital pins for the interface).

Here's some code that I wrote a long time ago to set LEDs
//The 74HC595 using a protocol called SPI (for more details
//Which has three pins
#define  DATA_PIN  10   
#define  CLOCK_PIN  9
#define  LATCH_PIN  8

void setup()
  // We set the three control pins to outputs
  pinMode(DATA_PIN, OUTPUT);
  pinMode(CLOCK_PIN, OUTPUT); 
  pinMode(LATCH_PIN, OUTPUT); 

void updateLEDs(byte value, boolean bReverse, int nPause)
// Handle the interface to the 74HC595 to write the 8 bits of the byte 
// Optionally invert the bit string and then delay at the end
  if (bReverse) value = ~value;

  digitalWrite(LATCH_PIN, LOW);  //Pulls the chips latch low
  shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, value); //Shifts out the 8 bits to the shift register
  digitalWrite(LATCH_PIN, HIGH);   //Pulls the latch high displaying the data
  if (nPause != 0) delay(nPause);
427  Using Arduino / Project Guidance / Re: digital pot on: October 12, 2013, 01:11:37 am
It can be done, just as you described.

Without any details of what the hardware is or how you have connected it, etc, you are probably not going to get much help.  If you have already written code then post that too.
428  Using Arduino / Programming Questions / Re: Is there any way to "delay()" (or equivalent) within an interrupt? on: October 11, 2013, 06:29:51 pm
Hard to give advice without any idea of the application.

What you can do is set a flag/status from the interrupt routine to signal that the interrupt has occurred. Then somewhere else (like loop()) count up time until the required delay has happened. You should always make your interrupt routines as fast as possible, so any form of lingering in the ISR is a generally bad idea.
429  Using Arduino / LEDs and Multiplexing / Re: Led Matrix 8x8 x5 max7219 on: October 11, 2013, 04:52:52 pm
Simplistically, you could take each of your animations and put them in a separate function (animation1, animation2, etc). In the main loop you then check if a button is pressed and if so, increment a variable with wraparound. The correct animation is then run through a case statement. Something like this:
void animation0()
// stuff in here

void animation1()
// etc for as many animations as you want, lets say MAX_ANIMATION

void loop()
  static int anim = 0;

  switch (anim)
  case 0:   animation0();  break;
  case 1:  animation1(); break;
// etc
  default: anim = 0;  // in case things go crazy :-)

  // check if the button is pressed
  if (buttonpressed)  // substitute your code here
    anim = (anim + 1) % MAX_ANIMATION;

I would encourage you to do this step as it will create a basic flow. However, what you will quickly find is that the animations changing is hard because the button is only detected once an animation is over (you are use the delay() function in the animation function), whereas as a user you would expect to have the change happen as soon as you press the button.

In order for the software to do what you expect you will need to use techniques shown in the BlinkWithoutDelay example, checking the timer rather than calling delay(). At that point you may find it more convenient to have the animation bit patterns as arrays because you need to remember where you were in the animation (ie, the array index of the last pattern sequence) every time the animation function is called. You set up the bit pattern array like this:
uint8_8 pattern0 [][8] =
  { B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000,B00010000 },
  { B00010000,B00010000,B00001000,B00000100,B00000010,B00000100,B00001000,B00010000 },
// etc - you get the idea

Then your code changes to be one animation routine called with a different pattern array (ie, the code becomes general and the data tells it what to do). This makes managing your code much easier and changing patterns becomes easier as well.

Hopefully this is enough of an explanation to get you going.
430  Using Arduino / Programming Questions / Re: 24X6 Led Matrix works BUT I want to add animations also. Need help!! on: October 11, 2013, 10:31:48 am
Ok then, good luck with your project.
431  Using Arduino / Storage / Re: Reading/writing struct to sd card on: October 11, 2013, 04:31:08 am
There is no = as per the error message. Think about what the function is doing. It is filling the memory from the SD card, so why are you needing to assign anything? Also, look at the function documentation to see what the return value  is.  People who write libraries document stuff so you can us their libraries more easily, but you do need to make the effort to read up on it to make sure you are using it properly.
432  Using Arduino / Storage / Re: Reading/writing struct to sd card on: October 11, 2013, 02:08:57 am
Most good libraries have a block read as well, to match the block write. In this case you will need to use a loop to read all the data in one byte at a time. Set a uint8_t pointer to the address of the data/struct and then for each byte you read, assign it to the 'pointed' location and increment the pointer, repeat.
433  Using Arduino / Programming Questions / Re: 24X6 Led Matrix works BUT I want to add animations also. Need help!! on: October 11, 2013, 01:59:01 am
Here's some guidance:

You need to think of the LEDs as pixels on a display and write a function that will turn on and off one pixel. To do this you need to decide where the origin (0,0) of the matrix is and then when the function to turn on pixel (x,y) you can do a translation of what that means for your hardware (ie, you need to control something to make it happen). Once you can do that, the rest is easy. You can write functions to do vertical, horizontal, arbitrary lines, circles, etc, because all they are is points turning on and off.

Bouncing balls are a pixel turned on, wait some time, pixel off and next pixel on (in the direction of travel), wait, etc. Edge detection changes the direction of the coordinate that goes out of boundary (ie, if we were adding one we now subtract one to the coordinate).

The MD_MAX72xx library in my repository (below) implements these sorts of function in a different situation, so you may be able to see what I have done there (not beginner code though).
434  Using Arduino / Storage / Re: Reading/writing struct to sd card on: October 11, 2013, 01:27:31 am
The SD library does have a block write function, pretty much like in my first reply. Extract from the library online manual:

file.write(buf, len)

file: an instance of the File class (returned by
data: the byte, char, or string (char *) to write
buf: an array of characters or bytes
len: the number of elements in buf

Using this method would be more efficient and faster, as you do it all in one statement.
435  Using Arduino / Storage / Re: Reading/writing struct to sd card on: October 10, 2013, 03:35:01 pm
A struct is just an area of memory. So if the SD library allows you to write a block of bytes (or an array of bytes), then you need to have something like this

writefunctionname((uint8_t *)&Pattern_var, sizeof(Pattern_var)/sizeof(uint8_t));

In other words, a pointer to the structure is cast as a pointer to whatever the function will take (uint8_t, int, or other). The number of these elements to be written is the sizeof the structure divided by the sizeof the element to be written. In this case the divisor would be 1 as uint8_t is size 1 byte.

If block writes are not available then a similar thing can be done but you need to write each element of the memory buffer individually (usually using a loop), incrementing the memory pointer for each element.
Pages: 1 ... 27 28 [29] 30 31 ... 86