Code:
Code: Select all
#define LED_1_PIN 5
#define LED_2_PIN 6
#define LED_3_PIN 3
#define LED_4_PIN 9
#define LED_5_PIN 10
#define LED_6_PIN 11
const int potPin = A0;
int readValue = 0;
int writeValue;
int brightness = 0;
int motorState = 0;
int inputVal = 0;
void setup()
{
Serial.begin(9600);
pinMode(potPin, INPUT);
pinMode(LED_1_PIN, OUTPUT);
pinMode(LED_2_PIN, OUTPUT);
pinMode(LED_3_PIN, OUTPUT);
pinMode(LED_4_PIN, OUTPUT);
pinMode(LED_5_PIN, OUTPUT);
pinMode(LED_6_PIN, OUTPUT);
}
void Potentiometer()
{
readValue = analogRead(potPin);
brightness = (255./1023.) * readValue;
if (readValue > 0)
{
vibrate();
}
}
void vibrate()
{
if(motorState == 0) {
analogWrite(LED_1_PIN, brightness);
analogWrite(LED_2_PIN, brightness);
analogWrite(LED_3_PIN, brightness);
analogWrite(LED_4_PIN, 0);
analogWrite(LED_5_PIN, 0);
analogWrite(LED_6_PIN, 0);
motorState = motorState + 1;
}
else if(motorState == 1)
{
analogWrite(LED_1_PIN, 0);
analogWrite(LED_2_PIN, 0);
analogWrite(LED_3_PIN, 0);
analogWrite(LED_4_PIN, brightness);
analogWrite(LED_5_PIN, brightness);
analogWrite(LED_6_PIN, brightness);
motorState = 0;
}
}
void loop()
{
static unsigned long previousMillis = 0;
if (millis() - previousMillis >= 500)
{
previousMillis += 500;
Potentiometer();
}
}