Go Down

Topic: capacity sensors and servo motors (Read 205 times) previous topic - next topic

charly_c

Hello! I'm a student and I'm building a interactive installation as part of my studies. I have 8 servo motors and they divided in 2 groups of 4, which means that 4 motors perform a sequence/effect and the other group of 4 performs another.

What I'm trying to achieve is that when someone touched sensor 1 it starts the first group of 4 motors, and when someone else touches sensor 2 it starts the second group of motors. I want them to be working independently, but simultaneously.

However, I have been trying several things and until one groups finishes the sequence, the other doesn't start. I think the way is to use timers but I'm confuse at the moment.

I'm using adafruit capacitive touch sensor board CAP 1188, and the library VarSpeedServo, that allows a group of servo to work in sequence.

Here is the code:

Code: [Select]



#include <Wire.h>
#include <SPI.h>
#include <Adafruit_CAP1188.h>
#include <VarSpeedServo.h>


unsigned long timer;

#define CAP1188_RESET  9

#define CAP1188_CS  10

#define CAP1188_MOSI  11
#define CAP1188_MISO  12
#define CAP1188_CLK  13

Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_RESET);

VarSpeedServo myservo1;
VarSpeedServo myservo2;
VarSpeedServo myservo3;
VarSpeedServo myservo4;

VarSpeedServo myservo5;
VarSpeedServo myservo6;
VarSpeedServo myservo7;
VarSpeedServo myservo8;


int number = 0;



void setup() {
  Serial.begin(9600);
  myservo1.attach(2);
  myservo2.attach(3);
  myservo3.attach(4);
  myservo4.attach(5);
  
  
  myservo5.attach(6);
  myservo6.attach(7);
  myservo7.attach(8);
  myservo8.attach(9);


  Serial.println("CAP1188 test!");

  if (!cap.begin(0x28)) {
    Serial.println("CAP1188 not found");
    while (1);
  }
  Serial.println("CAP1188 found!");
}

void loop() {
  uint8_t touched = cap.touched();

  for (uint8_t i=0; i<8; i++) {
    if (touched & (1 << i)) {
      Serial.print("C");
      Serial.print(i+1);
       Serial.print("\t");
      number = i + 1;

    }
  }

  
  timer = millis();


  if (number == 1 && touched > 0) { // lado 1 sensor (cima)

  myservo1.write(random (10,170),100,true);
  timer = 15;
  myservo2.write(random (10,170),100,true);
  timer = 15;
  myservo3.write(random (10,170),100,true);
  timer = 15;
  myservo4.write(random (10,170),100,true);
  timer = 15;

  myservo4.write(10,100,true);
timer = 15;
  myservo3.write(10,100,true);
timer = 15;
  myservo2.write(10,100,true);
timer = 15;
  myservo1.write(10,100,true);
timer = 15;
  
   number = 0;
  }

if (number == 3 && touched > 0) { // lado 2 sensor 2 (cima)

  myservo5.write(170,random (10,255),true);
  timer = 15;
  myservo6.write(170,random (10,255),true);
  timer = 15;
  myservo7.write(170,random (10,255),true);
  timer = 15;
  myservo8.write(170,random (10,255),true);
  timer = 10;

  myservo8.write(10,100,true);
  timer = 15;
  myservo7.write(10,100,true);
  timer = 15;
  myservo6.write(10,100,true);
  timer = 15;
  myservo5.write(10,100,true);
  timer = 100;
  
   number = 0;
  }
  


}





Could anyone give some piece of advice.

Thanks in advanced

charly_c

Sorry… but anyone has any idea?

thanks

Grumpy_Mike

#2
Jul 02, 2015, 02:10 am Last Edit: Jul 02, 2015, 02:11 am by Grumpy_Mike
You keep having the line
Code: [Select]
timer = 15;
What do you think it is doing?
It is not doing anything useful it is just putting the value of 15 in the variable timer.
If you want 15 in this variable you only have to do it once.

Go Up