Go Down

Topic: Thanks to all helpers (Read 347 times) previous topic - next topic

kaporal_p

Hello!

I've been trying to write a code for a relatively simple project for about a year now (hmmmm).

I finally got it to work, just now, and I want to thank everyone who helped me, bit by bit, to get here. I realize I have learned a lot through this project and it would have been impossible without the help of this community, so thanks again.

and sorry if I was sometimes annoying with my obvious questions...

so, for those interested here's the code: it's for an art project for a friend of mine, it will control five pair of papier-mache eyes, each pair sitting on a mushroom. Sensors will detect presence along a sidewalk and the mushrooms will turn their eyes toward the sensor that's activated.
The toughest part was to get the focus' to be concentric and not parallel (thanks to drhex for this one).

anyway here it is

Code: [Select]
#include <Servo.h>

Servo myservo[5];
int buttonPin[] = {2, 3, 4, 5, 6};
int buttonState[] = {0, 0, 0, 0, 0};
int lastButtonState[] = {0, 0, 0, 0, 0};
int positions[] = {90, 112, 134, 156, 178};
int rank[] = {0, 1, 2, 3, 4};
int x = 11 ;

void setup() {
 for (int serv=0;serv<5;serv++){
     myservo[serv].attach(x); x--;
 }

 for(int buttonPinning = 0; buttonPinning < 5; buttonPinning++){                                              
   pinMode (buttonPin[buttonPinning], INPUT);                                                                    
 }
}  
void moveButton() {                                                            
 for(int buttonRoll = 0; buttonRoll < 5; buttonRoll++){                                                      
 buttonState[buttonRoll] = digitalRead(buttonPin[buttonRoll]);                                                
   
   if ((buttonState[buttonRoll] != lastButtonState[buttonRoll])&&(buttonState[buttonRoll] == 1)) {
   for(int AservoRoll = 0; AservoRoll < 5; AservoRoll++){                                                                                                              
   myservo[AservoRoll].write(positions[AservoRoll]-(22*rank[buttonRoll]));
   }                                                                                                          
   delay(5);
   }
       else if ((buttonState[buttonRoll] != lastButtonState[buttonRoll])&&(buttonState[buttonRoll] == 0)){
       for(int BservoRoll = 0; BservoRoll < 0; BservoRoll++){                                                                                                                            
       myservo[BservoRoll].write(positions[BservoRoll]+(22*rank[buttonRoll]));
       }                                                                                                        
       delay(5);
       }
           else{                                                                                              
                     
           delay(5);
           }
       
   
     
 lastButtonState[buttonRoll] = buttonState[buttonRoll];                                                      
 }
}
void loop(){
 
 moveButton();
 
}
   
 
       


thanks again and see you at the next project!


Go Up