#include <Stepper.h>
#define motorSteps 100 // change this depending on the number of steps
// per revolution of your motor
#define motorPin1 7
#define motorPin2 8
// define pins for RGB light and pins for buttons for control RGB and focus
int data[7][9] = {
{255,255,160,190,190,80,90,90,34},
{255,0,0,80,0,0,30,0,0},
{0,255,0,0,100,0,0,50,0},
{0,100,255,0,0,255,0,0,170},
{255,153,0,160,100,0,100,70,0},
{255,0,200,160,0,100,100,0,35},
{0,0,0,0,0,0,0,0,0}
};
int redpin = 11; //select the pin for the red LED
int greenpin = 10; // select the pin for the green LED
int bluepin = 9;// select the pin for the blue LED
int i=0;
int j=0;
int col=2;// select the pin for change color
int brg=3;// select the pin for change brightness
int focpl=4;// select the pin for focus plus
int focmin=5;// select the pin for focus minus
// initialize of the Stepper library:
Stepper myStepper(motorSteps, motorPin1,motorPin2);
void setup() {
// set the motor speed at 10 RPMS:
myStepper.setSpeed(10);
pinMode(redpin, OUTPUT); pinMode(bluepin, OUTPUT); pinMode(greenpin, OUTPUT);
pinMode(col, INPUT); pinMode(brg, INPUT);
pinMode(focpl,INPUT); pinMode(focmin,INPUT);
}
void loop() {
if (((digitalRead(col)) == 1) or ((digitalRead(brg)) == 1)){
led();} // read buttons and if there is pressed - send to LED function
if (((digitalRead(focpl)) == 1) or ((digitalRead(focmin)) == 1)){
focus();} // read buttons and if there is pressed - send to stepper motor function
}
// LED function
void led(){
analogWrite(redpin, data[i][j]); analogWrite(greenpin, data[i][(j+1)]); analogWrite(bluepin, data[i][(j+2)]);
delay (600);
i=(i+digitalRead(col));
j=(j+(3*digitalRead(brg)));
delay (20);
if(i>=7){i=0;}
if(j>=9){j=0;}
}
// Focus function
void focus(){
// Step forward 1 step:
if (digitalRead(focpl) == 1) {
myStepper.step(1);}
delay(100);
// Step backward 1 step:
if (digitalRead(focmin) == 1) {
myStepper.step(-1);}
delay(100);
}
Comments