Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / How do I move a sequence through an array? on: April 18, 2014, 05:33:44 pm

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........."
until at the end it would start to loop around again...

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

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..
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

I will put future code updates here...
3  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.
4  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..
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.
5  Using Arduino / Programming Questions / Convert an int to char array, then append another char on: July 31, 2013, 08:28:20 am
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.

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?
6  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..
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
7  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.
8  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?
9  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.
10  Using Arduino / Project Guidance / Odometry to Cartesian calculations - calculating bearing on: January 04, 2013, 05:33:20 pm

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.,%20by%20David%20Anderson.htm

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

theta = 0;

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?
11  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.

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]