Relais Drum Machine
Basic example to control on/off speed of three relais using three sensors.
/* relais drum machiine * * using 3 sensors to control on/off speed of 3 relais (e.g. distance sensor) * * based on the examples "Toggle led" and "Metro" * * uses metro library (http://www.arduino.cc/playground/Code/Metro) * * SensorAktor Workshop * Lab3 2008 * Kunsthochschule fuer Medien Koeln * Academy of Media Arts Cologne * http://interface.khm.de * pin mapping SensorAktor Shield * import SensorAktor.h to get already defined mapping * * analog inputs: analog0 = pin0, analog1 = pin1, analog2 = pin2, * analog3 = pin3, analog4 = pin4, analog5 = pin5 * built-in poti: poti = pin5 * amplified input: mic = pin0 * switches: switch1 = pin1, switch2 = pin2, switch3 = pin3 * leds: led1 = pin3, led2 = pin5, led3 = pin6 * power outs: out1 = pin3, out2 = pin5, out3 = pin6 * motor outs: motor1_1 = pin8, motor1_2 = pin13, motor2_1 = pin11, motor2_2 = pin12 * motor pwms: pwmMotor1 = pin10, pwmMotor2 = pin9 * servo outs: servo1 = pin2, servo2 = pin4, servo3 = pin7 */ // import sensor aktor library for pin mapping #include <SensorAktor.h> // import metro library #include <Metro.h> // set relais metros Metro relaisMetro1 = Metro(1000); Metro relaisMetro2 = Metro(1000); Metro relaisMetro3 = Metro(1000); // states relais int relaisState1 = 0; int relaisState2 = 0; int relaisState3 = 0; // sensor values int sensorValue1 = 0; int sensorValue2 = 0; int sensorValue3 = 0; // this block is executed one time when programm starts void setup(){ // pin modes pinMode(out1,OUTPUT); pinMode(out2,OUTPUT); pinMode(out3,OUTPUT); } // this block is executed in a loop after setup is called one time void loop(){ // check relais metro 1 if(relaisMetro1.check() == 1){ if(relaisState1 == 0){ digitalWrite(out1,HIGH); relaisState1 = 1; } else{ digitalWrite(out1,LOW); relaisState1 = 0; } } // check relais metro 2 if(relaisMetro2.check() == 1){ if(relaisState2 == 0){ digitalWrite(out2,HIGH); relaisState2 = 1; } else{ digitalWrite(out2,LOW); relaisState2 = 0; } } // check relais metro 3 if(relaisMetro3.check() == 1){ if(relaisState3 == 0){ digitalWrite(out3,HIGH); relaisState3 = 1; } else{ digitalWrite(out3,LOW); relaisState3 = 0; } } // read sensor values sensorValue1 = analogRead(analog1); sensorValue2 = analogRead(analog2); sensorValue3 = analogRead(analog3); // mapping (in our setup we use distance sensor, which have a range from 70 to 600) sensorValue1 = map(sensorValue1, 70, 600, 300, 10); sensorValue2 = map(sensorValue2, 70, 600, 300, 10); sensorValue3 = map(sensorValue3, 70, 600, 300, 10); // set speed metros using mapped sensor values relaisMetro1.interval(sensorValue1); relaisMetro2.interval(sensorValue2); relaisMetro3.interval(sensorValue3); }
Files needed
Since Arduino 0015 there are some problems with the old “SensorAktor.h” file.
Use this one instead.