Show Posts
Pages: 1 ... 6 7 [8] 9 10 ... 22
106  Community / Gigs and Collaborations / Re: Help with a basic code on: June 03, 2014, 07:43:56 am
Hello Wayne,

Another version of the code with the last step in the sequence sweeping into and from the last step in 10 seconds attached and inline for you.

Code:
// ===================================================================================
// = library includes              =
// ===================================================================================
#include <avr/eeprom.h>
#include <Servo.h>
#include <Time.h> 

// ===================================================================================
// = Servo object instatiation              =
// ===================================================================================
Servo oServo; 

// ===================================================================================
// = Global variable to hold time and interval =
// ===================================================================================
time_t NextEvent;

#define Interval 1 //this is 600 seconds or 10 minutes

// ===================================================================================
// = Array to hold servo positions              =
// =   these are the servo PWM signals that you will need to tune to your servo      =
// ===================================================================================
int ServoPos[] = {1000,1080,1160,1240,1320};

// ===================================================================================
// = Structure to hold state              =
// ===================================================================================
struct ServoParams_t
{
int Position;
int Direction;
} ServoParams;


// ===================================================================================
// = Setup code              =
// ===================================================================================
void setup()
{

Serial.begin(9600);
oServo.attach(9); // Attach the oServo object to use pin 9
LoadSettings(); // Read from the EEPORM

if(ServoParams.Position > 4) ServoParams.Position = 4; // just a bit of safety in the case of the EEPROM value being out of range
if(ServoParams.Position < 0) ServoParams.Position = 0; // just a bit of safety in the case of the EEPROM value being out of range
if(ServoParams.Direction > 1) ServoParams.Direction = 1; // just a bit of safety in the case of the EEPROM value being out of range
if(ServoParams.Direction < -1) ServoParams.Direction = -1; // just a bit of safety in the case of the EEPROM value being out of range

NextEvent = now() + (Interval); // Set the first interval time

}
 
 
// ===================================================================================
// = Main Program loop              =
// ===================================================================================
void loop()
{
if(now() >= NextEvent)
{
SaveSettings();  // Store state in EEPROM
ServoParams.Position += ServoParams.Direction; // Increment or decrement the servo posistion array pointer
if (ServoParams.Position == 4 )
{
Serial.println(ServoPos[ServoParams.Position]);
int CurrentPos = ServoPos[3];
int DestPos = ServoPos[4];
int msSteps = 10000/ (DestPos - CurrentPos);
for(int SweepPos = CurrentPos;SweepPos < DestPos;SweepPos++ )
{
oServo.write(SweepPos);  // Write value to oServer Object
delay(msSteps/2);
}

for(int SweepPos = DestPos;SweepPos > CurrentPos;SweepPos-- )
{
oServo.write(SweepPos);  // Write value to oServer Object
delay(msSteps/2);
}
ServoParams.Direction = -ServoParams.Direction;
}
else
{
if (ServoParams.Position <= 0) ServoParams.Direction = -ServoParams.Direction; // check for range end and swap direction
oServo.write(ServoPos[ServoParams.Position]);  // Write value to oServer Object
Serial.println(ServoPos[ServoParams.Position]);
}
NextEvent = now() + (Interval);
}
}


// ===================================================================================
// = EEPROM Storage Handlers              =
// ===================================================================================

void LoadSettings(void)
{
eeprom_read_block((void*)&ServoParams, (void*)(sizeof(ServoParams)), sizeof(ServoParams));
}

void SaveSettings(void)
{
eeprom_write_block((const void*)&ServoParams, (void*)(sizeof(ServoParams)), sizeof(ServoParams));
}


Cheers Pete.
107  Community / Gigs and Collaborations / Re: MIDI input to PWM output on: June 03, 2014, 02:46:15 am
OK ... there is some confusion on your part going on here.

A motor cannot be used to play tones, at least not the way you are planning to using a variable frequency drive. You could get it to spin at different speeds and that would create a series of tones.

Why a motor for the OP device (unless you really are hacking a vibrator in which case i understand and require no further information)

Also what is you end goal on this. I am not sure i understand what the application is (again unless it really is a vibrator)

Cheers Pete.
108  Community / Gigs and Collaborations / Re: Help with a basic code on: June 02, 2014, 10:53:57 am
Hi Wayne,

OK so here is the code again tested against my Futaba RC servo that I use in my camera gimbal on my quatcopter.

Attached and in the thread.

It is running a full 90 deg rotation.

If you only want 45 deg then divide the values in the array by 2

 I.E. int ServoPos[] = {1000,1080,1160,1240,1320};

It is currently moving every second using the timing variable that you have already worked out how to adjust.

Have Fun

Cheers Pete.

Code:
// ===================================================================================
// = library includes             =
// ===================================================================================
#include <avr/eeprom.h>
#include <Servo.h>
#include <Time.h>  

// ===================================================================================
// = Servo object instatiation             =
// ===================================================================================
Servo oServo;  

// ===================================================================================
// = Global variable to hold time and interval =
// ===================================================================================
time_t NextEvent;

#define Interval 1 //this is 600 seconds or 10 minutes

// ===================================================================================
// = Array to hold servo positions             =
// =   these are the servo PWM signals that you will need to tune to your servo      =
// ===================================================================================
int ServoPos[] = {1000,1160,1320,1480,1640};

// ===================================================================================
// = Structure to hold state             =
// ===================================================================================
struct ServoParams_t
{
int Position;
int Direction;
} ServoParams;


// ===================================================================================
// = Setup code             =
// ===================================================================================
void setup()
{

Serial.begin(9600);
oServo.attach(9); // Attach the oServo object to use pin 9
LoadSettings(); // Read from the EEPORM

if(ServoParams.Position > 4) ServoParams.Position = 4; // just a bit of safety in the case of the EEPROM value being out of range
if(ServoParams.Position < 0) ServoParams.Position = 0; // just a bit of safety in the case of the EEPROM value being out of range
if(ServoParams.Direction > 1) ServoParams.Direction = 1; // just a bit of safety in the case of the EEPROM value being out of range
if(ServoParams.Direction < -1) ServoParams.Direction = -1; // just a bit of safety in the case of the EEPROM value being out of range

NextEvent = now() + (Interval); // Set the first interval time

}
 
 
// ===================================================================================
// = Main Program loop             =
// ===================================================================================
void loop()
{
if(now() >= NextEvent)
{
SaveSettings();  // Store state in EEPROM
NextEvent = now() + (Interval); // Set the next interval time
ServoParams.Position += ServoParams.Direction; // Increment or decrement the servo posistion array pointer
if (ServoParams.Position >= 4 || ServoParams.Position <= 0) ServoParams.Direction = -ServoParams.Direction; // check for range end and swap direction
oServo.write(ServoPos[ServoParams.Position]);  // Write value to oServer Object
Serial.println(ServoPos[ServoParams.Position]);
}
}


// ===================================================================================
// = EEPROM Storage Handlers             =
// ===================================================================================

void LoadSettings(void)
{
eeprom_read_block((void*)&ServoParams, (void*)(sizeof(ServoParams)), sizeof(ServoParams));
}

void SaveSettings(void)
{
eeprom_write_block((const void*)&ServoParams, (void*)(sizeof(ServoParams)), sizeof(ServoParams));
}
109  Community / Gigs and Collaborations / Re: Help with a basic code on: June 02, 2014, 10:08:24 am
Hi Wayne,

Sure sorry i got caught up with the family on the weekend . I will get to it today for you.

Cheers Pete.
110  Community / Gigs and Collaborations / Re: MIDI input to PWM output on: June 01, 2014, 07:56:56 am
this sounds a little confusing...

MIDI to PWM ..

OK PWM is Pulse WIDTH modulation not Frequency modulation. The frequency of the square wave remains the same it is only the mark/space ratio that changes. where does "tone/frequency" come into this.

When you say drive a motor , what kind ? if it is a standard RC Servo that takes PWM 1-2 ms with a 20ms duty cycle then you are adjusting the mark/space ratio and not the frequency. If you are intending that it should approximate an analogue output to drive a motor a different speeds (also PWM not Frequency) then you really should be looking at an external motor driver or ESC like those found on RC  gear.

Cheers Pete.
111  Community / Gigs and Collaborations / Re: Help with a basic code on: June 01, 2014, 03:02:57 am
OK I tell you what i will set this up on my UNO with a servo and video it for you. I am not about today daytime but i will get to it this evening for you.

Cheers Pete.
112  Community / Gigs and Collaborations / Re: Help with a basic code on: May 31, 2014, 07:42:27 am
OK so here it is for a "dumb ass" smiley

in the code you need to look for the line that looks like this

byte ServoPos[] = {0,51,102,204,255};

Now in simple terms this is a list of the location that the servos will move to and then back through.

Since I dont have your servo I CANNOT give you the ACTUAL numbers you need to put in here.

However it is a simple process to replace each number (by trial and error) with one that moves the servo to the position that you  want it to be for that stage of the pattern.

Now looking at the values that are in the array by default (the ones i used) you have (assuming a 10 second step time)
@ 0  Seconds 0
@ 10 Seconds 51
@ 20 Seconds 102
@ 30 Seconds 204
@ 40 Seconds 255

What you need to be doing is changing the value that the servo gets for each of the time slots

The easy way to do this is to use the sweep program and work out the limits of the servo.

as a guess i would try using the following values

byte ServoPos[] = {0,10,20,30,45};

These values should move it according to your ORIGINAL requirement of 0-45 deg and back in 5 steps


Cheers Pete.
113  Community / Gigs and Collaborations / Re: Help with a basic code on: May 31, 2014, 01:30:16 am
Hi Wayne,


Like I explained in the message i sent to you with the code  you have to adjust the values in the array to match the positions that you want to see

byte ServoPos[] = {0,51,102,204,255};  each of thes represents 5,10,15,20,25 min intervals and then it moved back down again.

Cheers Pete.
114  Community / Gigs and Collaborations / Re: Help with a basic code on: May 30, 2014, 03:37:41 pm
no worries it is my bedtime now I'll catch up in the morning

Cheers Pete.
115  Community / Gigs and Collaborations / Re: Help with a basic code on: May 30, 2014, 03:26:37 pm
Hi Wayne

I sent you a personal message with the links to the full instructions here it is again in case you have missed it somehow

Here follow this link and install the "Time" library

http://arduino.cc/en/Guide/Libraries

you can find the time library here
http://playground.arduino.cc/uploads/Code/Time.zip

Cheers Pete.
116  Community / Gigs and Collaborations / Re: Help with a basic code on: May 30, 2014, 02:49:18 pm
HI Wayne,

OK so you have the code and instructions on how to install the "time" library. Now that you have it when are you planning on paying me ?

Cheers Pete.
117  Community / Gigs and Collaborations / Re: Help needed on race car project on: May 30, 2014, 02:47:33 pm
HI Andy,

 What is your budget on this. I may be interested.

Cheers Pete.
118  Community / Gigs and Collaborations / Re: Help with a basic code on: May 29, 2014, 12:37:18 pm
Thanks Mate
Its 3 AM so I am off to bed will pick up in say 5 hours

OK no worries .. here is the code

Not SUPER elegant but functional.

There are some variables you will need to play with yourself to get it turning to the exact positions that you want.
They are the numbers in the array ServoPos[]

Code Attached, have fun with it.

I have PM'ed you my PayPal details.

Cheers Pete.

119  Community / Gigs and Collaborations / Re: Help with a basic code on: May 29, 2014, 11:46:49 am
I can paypal you when you are done
Thanks
Wayne

OK leave it with me for an hour

Cheers Pete.
120  Community / Gigs and Collaborations / Re: Help with a basic code on: May 29, 2014, 11:31:11 am
Yep you have it smiley
Pages: 1 ... 6 7 [8] 9 10 ... 22