programing help
 
Notifications
Clear all

programing help

5 Posts
3 Users
0 Reactions
3,215 Views
Posts: 7
Topic starter
(@gloschkid)
Active Member
Joined: 13 years ago
[#30681]

hello,i need a little help with my programming i have an osepp mega 2560 running 35 pwm chanels and what id like it to do is look for a header from the generic serial to stay synced here is my code


#include <SoftPWM.h>
int c1 = 13;  
int c2 = 18; 
int c3 = 10;  
int c4 = 9;  
int c5 = 8;
int c6 = 7;
int c7 = 6;
int c8 = 5;
int c9 = 4;
int c10 =3;
int c11 = 2;
int c12 = 22; 
int c13 = 23;
int c14 = 24;
int c15 = 25;
int c16 = 26;
int c17 = 27;
int c18 = 28;
int c19 = 29;
int c20 = 30;
int c21 = 31;
int c22 = 32;
int c23 = 33;
int c24 = 34;
int c25 = 35;
int c26 = 36;
int c27 = 37;
int c28 = 38;
int c29 = 39;
int c30 = 40;
int c31 = 41;
int c32 = 42;
int c33 = 15;
int c34 = 16;
int c35 = 17;




int incomingByte[35];


void setup()
	{
  		SoftPWMBegin();
                Serial.begin(57600);
  		for (int i =1; i <= 1000; i++)
    		{
      			SoftPWMSet(i, 255);
    		}
	}


void loop()
	{
		if (Serial.available() >= 35)
			{
				
				for (int i = 0; i <= 36;i++)
					{
						
						incomingByte[i] = Serial.read();
					}

				SoftPWMSet(c1, incomingByte[0]); 
				SoftPWMSet(c2, incomingByte[1]); 
				SoftPWMSet(c3, incomingByte[2]); 
				SoftPWMSet(c4, incomingByte[3]); 
				SoftPWMSet(c5, incomingByte[4]); 
				SoftPWMSet(c6, incomingByte[5]); 
				SoftPWMSet(c7, incomingByte[6]); 
				SoftPWMSet(c8, incomingByte[7]); 
				SoftPWMSet(c9, incomingByte[8]); 
				SoftPWMSet(c10, incomingByte[9]);
				SoftPWMSet(c11, incomingByte[10]); 
				SoftPWMSet(c12, incomingByte[11]);
                                SoftPWMSet(c13, incomingByte[12]);
                                SoftPWMSet(c14, incomingByte[13]);
                                SoftPWMSet(c15, incomingByte[14]);
                                SoftPWMSet(c16, incomingByte[15]);
                                SoftPWMSet(c17, incomingByte[16]);
                                SoftPWMSet(c18, incomingByte[17]);
                                SoftPWMSet(c19, incomingByte[18]);
                                SoftPWMSet(c20, incomingByte[19]);
                                SoftPWMSet(c21, incomingByte[20]);
                                SoftPWMSet(c22, incomingByte[21]);
                                SoftPWMSet(c23, incomingByte[22]);
                                SoftPWMSet(c24, incomingByte[23]);
                                SoftPWMSet(c25, incomingByte[24]);
                                SoftPWMSet(c26, incomingByte[25]);
                                SoftPWMSet(c27, incomingByte[26]);
                                SoftPWMSet(c28, incomingByte[27]);
                                SoftPWMSet(c29, incomingByte[28]);
                                SoftPWMSet(c30, incomingByte[29]);
                                SoftPWMSet(c31, incomingByte[30]);
                                SoftPWMSet(c32, incomingByte[31]);
                                SoftPWMSet(c33, incomingByte[32]);
                                SoftPWMSet(c34, incomingByte[33]) ;
                                SoftPWMSet(c35, incomingByte[34]);
			}
	}

oh and any help understanding how to use this line

for (int i =1; i <= 1000; i++)

would help i just through random numbers in there ( im only 14 and im steel learning how to use the arduino)
heres a video on my first test :biggrin:

thanks in advance 😆


4 Replies
Posts: 352
(@pmscientist)
Reputable Member
Joined: 16 years ago

You'll have to switch to a Vixen output type other than generic serial to do this. Renard is probably easiest. I'd take a look at the FoxCub documentation on the wiki as a start. There are also several posts here about getting Arduino code that works with the Vixen and Renard serial output.

The specific line you ask about is just a for loop. The part that actually 'does work' in that section is the call to SoftPWMSet(). You should read up on the Arduino/Wiring SoftPWM library. I don't know that library too well, but it says it only supports 20 channels. If the library passes through information to the hardware PWM pins as well, you could get 35 channels out of it. However, there's a good chance you'll have to rework the code to control 15 hardware and 20 software pwm channels to get to 35.

Since you're just getting started, it may be easiest to start by splitting this into 3 problems:
1) Accept Renard serial input and print out the data via the serial port
2) Serial control of the hardware PWM pins
3) Serial control of pins under SoftPWM control

Once all three of those are working on their own, then it'll be time to combine the different parts until you get everything into one program (sketch if you prefer).

Hope this helps get you going in the right direction.


Reply
Posts: 7
Topic starter
(@gloschkid)
Active Member
Joined: 13 years ago

thank you I moded it sothat there are 40 channels in the library and it works I just need iyt to receeve a header like start or begin so it nows where to look fotr incoming bits
heres a video of my code running:

by the way im 14 and have arly any programming experience but I don't whant to go with renard I want to be able to use all 54 pins as pwm or most of them so soft pwm is working


Reply
TazChaLet
Posts: 3042
(@tazchalet)
Famed Member
Joined: 13 years ago
gloschkid wrote:thank you I moded it sothat there are 40 channels in the library and it works I just need iyt to receeve a header like start or begin so it nows where to look fotr incoming bits
heres a video of my code running:

by the way im 14 and have arly any programming experience but I don't whant to go with renard I want to be able to use all 54 pins as pwm or most of them so soft pwm is working

This content is currently unavailable
The page you requested cannot be displayed right now. It may be temporarily unavailable, the link you clicked on may have expired, or you may not have permission to view this page. not sure if site is down or what


Reply
Posts: 7
Topic starter
(@gloschkid)
Active Member
Joined: 13 years ago

here you go


Reply
Share: