Hi everybody, I am new on this forum, but am using Arduino to control my DCC network for model trains.
The Subject chosen indicate a simple task, which is even more frustrating not to succeed with.
For this project I am using a ProMini; What I want to do is control 8 servos by means of
8 switches(“8” simply since ProMini has 16 usable pins). I can do this with ONE servo/switch, so I think I
understand how Software Servo works, but when introducing For-loops it doesn’t work anymore. The
code compiles ok, but the connected servo does nothing. I am more or less convinced there is some kind
of indexing error, or even simpler than that, so I humbly ask for a look at the code, with more
experienced eyes than mine.
The code:
//Code to control Servos
#include <SoftwareServo.h>
SoftwareServo servo1; // create servo object to control servos
int sw_val1 = 0;
int to_left = 50;
int to_right = 150;
int swpins= {11,12,13,14,15,16,17,18}; // define switchpins
int fpins= {3,4,5,6,7,8,9,10}; // define servopins
int index;
void setup()
{
for (int index = 0; index < 8; index++)
{servo1.attach(fpins[index]);
{pinMode(swpins[index], INPUT);
digitalWrite(swpins[index],HIGH);
}
}
}
void loop()
{ for (int index = 0; index < 8; index++)
{ int val = digitalRead(swpins[index]);
if (val = LOW)
{
servo1.write(index),(to_left);
}
else
{
servo1.write(index),(to_right);
}
}
SoftwareServo::refresh();
}
Regards
Peter in Sweden