Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: How do I move a sequence through an array? on: April 20, 2014, 04:46:40 am
So this is what I have which is working though I'm not sure it is the most efficient way. Suggestions for improving it are welcome.
Code:
// ledStringGREEN[] contains a pattern which is the same length of the LED strip (72 bytes) (actually a short pattern and then trailing zeros)

// PASS RGB DATA TO LED STRING
  for(int ledNo = 0; ledNo < numLEDs; ledNo++) {
     ledString[ledNo].setRGB(0, ledStringGREEN[ledNo], 0);
  }
 
  // ROTATE PATTERN BY 1
  int temp = ledStringGREEN[sequencePosition]; // Store first item in array
  for(int i = numLEDs-1; i >= 0; i--) {
    ledStringGREEN[i] = ledStringGREEN[i - 1]; // Rotate array   
  }
  ledStringGREEN[numLEDs] = temp; // Put the first item at the end
     
  FastLED.show();  // SENDS TO LEDS
  delay(50);
sequencePosition = (sequencePosition + 1) % numLEDs; // increments sequence in loop
I'm thinking a better approach would be one where I could insert short patterns n number of times and move them around the strip independently.
2  Using Arduino / Programming Questions / Re: How do I move a sequence through an array? on: April 19, 2014, 10:31:04 am
Thank you. I understand what the modulo does, but I don't understand how it helps to achieve my goal. That is what I was hoping for an example of. It's been ages since I last did some coding and I think the basic math part of my brain has fallen into disrepair!
3  Using Arduino / Programming Questions / Re: How do I move a sequence through an array? on: April 19, 2014, 10:14:14 am
Thankyou. Could you please give me an example of how of use the modulo operator to get the pattern to wrap around.
4  Using Arduino / Programming Questions / How do I move a sequence through an array? on: April 18, 2014, 05:33:44 pm
Hi,

I want to make a specific pattern move through an array for a neopixel type LED project.

For example; I have a pattern of LED brightness represented by an array "5,8,26,9" and I have an LED strip with 100 LEDS.
The full LED strip is represented by a 100 position array. I want to move the pattern along one LED at a time.
So the at first, the LED array would look like... "9,0,0,0,0,0,0,0........."
then "26,9,0,0,0,0,0,0,0........."
8,26,9,0,0,0,0,0,0,0.........
5,8,26,9,0,0,0,0,0,0.........
0,5,8,26,9,0,0,0,0,0.........
0,0,5,8,26,9,0,0,0,0.........
until at the end it would start to loop around again...
.....0,0,0,0,0,0,5,8,26,9
9,0,0,0..........0,0,0,5,8,26
26,9,0,0,0..........0,0,0,5,8

Any suggestions for a good way of doing that?
5  Development / Other Software Development / Adjustable Frequency PWM 1Hz to 2MHz with LCD Menu Display on: August 15, 2013, 05:11:58 am
Hi,

I just finished my first library (well a modification of an existing one) and want to post the library and sample code. Is this the right place to put it?

The library is called "NanoPWMac". It will output a bipolar signal using the two pins, i.e. when one is high, the other is low and vice-versa.
You can set it like this..
Code:
long frequency = 100000; // The frequency in Hz
long pulseWidth = 125; // The width of the output pulse in nanoseconds
NanoPWMac(frequency, pulseWidth); // Activates the output signal

The minimum step for the pulse width is 125ns. If you enter a number not divisible by 125ns, then the library will just round it down.

I've attached the library, and the code I used to make a nice adjustable PWM pulse generator with LCD menu. The device I wrote the code for is the RMCybernetics PDI-1
http://www.rmcybernetics.com/shop/cyber-circuits/signal-control/programmable-usb-device-pdi1

I will put future code updates here...
http://www.rmcybernetics.com/projects/code/index.htm
6  Using Arduino / Programming Questions / Re: Convert an int to char array, then append another char on: August 03, 2013, 01:22:54 pm
Thanks guys. I've used a combination of these in my code to get everything displayed nice.
7  Using Arduino / Programming Questions / Re: Convert an int to char array, then append another char on: July 31, 2013, 03:06:21 pm
Thanks. Sorry I missed something quite important!  smiley-red
There should be a line..
Code:
float reducedNo = number/1000
And i should have been asking how to convert a float! [facepalm]

So this means sprintf wont work as it does not like floats on the arduino.
itoa also wants an int

Basically what I am trying to do is display a frequency on an LCD that can be anything from 0 to 2 million. I'm hoping to make the larger numbers easier to read by making them look like 10k instead of 10000.
8  Using Arduino / Programming Questions / Convert an int to char array, then append another char on: July 31, 2013, 08:28:20 am
Hi,
I'm trying to convert an int to a char array then append another char on the end. This is to be outputted to an LCD. I keep getting stuck when trying to follow examples on the web.

Code:
long number = x;   //value from user input 0 to 2million
char buf[12];         // Output buffer
char suffix[2];       // suffix for appending to number (k or M)
int thousands = (number/1000);
suffix[0] = 'k';
itoa(reducedNo, buf, 10);   // convert number to text
buf+=suffix; //invalid operands to binary operator+

My brain has melted now. Does anyone have a good way to do this without using String?
9  Using Arduino / Project Guidance / Re: Odometry to Cartesian calculations - calculating bearing on: January 05, 2013, 03:46:49 pm
Thank you, it was simply my improper use of variable types that was giving me the problems. For reference here is the code I used for making it work..
      
Code:
double PI = 3.14159265359;
double TWOPI = PI * 2;
double ticksPerM = 105;  // Odometer pulses per meter
double wheelBase = 0.35; // Wheelbase in meters
double pixelsPerMeter = 10; // Multiplier for how many pixels represent 1m

double distance = ((m_odometerVals[0]/ticksPerM) + (m_odometerVals[1]/ticksPerM)) / 2; // Calculate distance moved in meters
theta += ((((m_odometerVals[0]/ticksPerM) - (m_odometerVals[1]/ticksPerM)) / wheelBase)); // Accumulate change in bearing;
theta -= ((double)((int)(theta/TWOPI))*TWOPI); // clip to +/- 360
xPos += pixelsPerMeter * distance * sin(theta);
yPos += pixelsPerMeter * distance * cos(theta);

PlotPoint((int)xPos,(int)yPos); // Plot the pixel on the screen
10  Using Arduino / Project Guidance / Re: Odometry to Cartesian calculations - calculating bearing on: January 04, 2013, 06:05:37 pm
if theta = 100, then isn't (100/TWOPI)*TWOPI just 100 again?  (TWOPI is 6.284....)

When I use this code, theta always comes out as 0.
As you probably guessed I suck at maths. I don't see where you got 360 from.
11  Using Arduino / Project Guidance / Re: Alarm system and radio transmission on: January 04, 2013, 05:43:56 pm
Secure in what sense? From people hacking the wireless link? What if people just bypass your sensors with a wire?
12  Using Arduino / Project Guidance / Re: Detection of moving object with signature on: January 04, 2013, 05:40:54 pm
You will need to use multiple receivers so that you can triangulate the position of the transmitting object. You can use the difference in intensity of each signal to work out a bearing.

Your Arduino will need to be able to sample both the intensity of the RF signal, and also be able record the signal so that they can be individually identified.

There are many practical difficulties in this however. Some research will give you more.
13  Using Arduino / Project Guidance / Odometry to Cartesian calculations - calculating bearing on: January 04, 2013, 05:33:20 pm
Hi,

I have a robot using differential drive and with a quadrature encoder on each motor. I'm trying to plot its position on a screen based on the odometry data. I have this example of calculation, but am having difficulty with the calculation for bearing.

http://www.seattlerobotics.org/encoder/200610/article3/IMU%20Odometry,%20by%20David%20Anderson.htm

I've simplified the example for the above link in the code below.

Code:
theta = 0;
WHEEL_BASE = 20;

void loop {
                L_Dis = GetOdometer(L);  // Get odometer reading (distance since last sample)
                R_Dis = GetOdometer(R);  // Get odometer reading (distance since last sample)

                distance = (L_Dis + R_Dis ) / 2; // Calculate total distance travelled

                theta += (L_Dis - R_Dis ) / WHEEL_BASE; // Accumulate total rotation
                theta -= (float)((int)(theta/TWOPI))*TWOPI; //Clip the rotation to plus or minus 360 degrees

/* now calculate and accumulate our position in inches */
                Y_pos += distance * cos(theta);
                X_pos += distance * sin(theta);
 }

To me it looks like theta would just become zero every time.  the line commented "Clip the rotation to plus or minus 360 degrees" seems to basically subtract theta from theta.

Does anyone have any suggestions or similar examples for converting odometry data to a Cartesian coordinate?
14  Community / Exhibition / Gallery / Robot platform for automatic obstacle avoidance on: December 13, 2012, 01:37:06 pm
Hi, this is the start of my project do demonstrate the use of fuzzy algorithms for avoiding obstacle.

http://www.rmcybernetics.com/projects/DIY_Devices/diy-robot-arduino.htm

I have built the code using a system of "urges" which control the behaviour of the machine. Next I will be adding further processors that will interface with this for manipulating these urges so that it can show more complex behaviour.
Pages: [1]