...

пятница, 15 июня 2018 г.

Макияж для кибер золушки. Arduino проект выходного дня. Светодиодные ресницы

#include <PinChangeInt.h>

#define   LEFT_PIN_1       2
#define   LEFT_PIN_2       3
#define   LEFT_PIN_3       4
#define   RIGHT_PIN_1      5
#define   RIGHT_PIN_2      6
#define   RIGHT_PIN_3      7
#define   KEY_PIN          8

#define   EFFECT_0         0
#define   EFFECT_1         1
#define   EFFECT_2         2
#define   EFFECT_3         3
#define   EFFECT_4         4
#define   EFFECT_5         5
#define   EFFECT_6         6
#define   EFFECT_7         7
#define   EFFECT_LAST      EFFECT_7
uint8_t EffectCnt = 0;

void setup()
{
  pinMode(LEFT_PIN_1, OUTPUT);
  pinMode(LEFT_PIN_2, OUTPUT);
  pinMode(LEFT_PIN_3, OUTPUT);
  pinMode(RIGHT_PIN_1, OUTPUT);
  pinMode(RIGHT_PIN_2, OUTPUT);
  pinMode(RIGHT_PIN_3, OUTPUT);
  pinMode(KEY_PIN, INPUT);
  digitalWrite(KEY_PIN, HIGH);
  PCintPort::attachInterrupt(KEY_PIN, &Key_ISR, FALLING);
}
//------------------------------------------------------
void loop()
{
  void (*EFFECTS[])(void) = { Lashes_0, Lashes_1, Lashes_2,
                              Lashes_3, Lashes_4, Lashes_5,
                              Lashes_6, Lashes_7, };    
                              
  (*EFFECTS[EffectCnt])();//EffectCnt

  delay(100);
  Lashes_Off();
  while(!digitalRead(KEY_PIN));
  delay(300);
  PCintPort::attachInterrupt(KEY_PIN, &Key_ISR, FALLING);
}
//------------------------------------------------------
void Lashes_0()
{
  const uint16_t ViewDelay = 5;
  
  while(EffectCnt == EFFECT_0)
  {
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);
    digitalWrite(RIGHT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
  }
}
//------------------------------------------------------
void Lashes_1()
{
  const uint16_t ViewDelay = 5;
  const uint8_t LashesON = 27;
  const uint16_t PauseDelay = ViewDelay * LashesON * 3;
  
  while(EffectCnt == EFFECT_1)
  {
    for (uint8_t i = 0; i < LashesON; i++)
    {
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);
    digitalWrite(RIGHT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
    }

    Lashes_Off();
    delay(PauseDelay);
  }
}
//------------------------------------------------------
void Lashes_2()
{
  const uint16_t ViewDelay = 5;
  const uint8_t LashesON = 17;
  
  while(EffectCnt == EFFECT_2)
  {
    for (uint8_t i = 0; i < LashesON; i++)
    {
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
    digitalWrite(RIGHT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
    }
    
    Lashes_Off();

    for (uint8_t i = 0; i < LashesON; i++)
    {
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    delay(ViewDelay);
    }

    Lashes_Off();
  }
}
//------------------------------------------------------
void Lashes_3()
{
  const uint16_t ViewDelay = 70;

  pinMode(LEFT_PIN_1, OUTPUT);
  pinMode(RIGHT_PIN_1, OUTPUT);
  pinMode(LEFT_PIN_2, INPUT);
  pinMode(RIGHT_PIN_2, INPUT);
  pinMode(LEFT_PIN_3, OUTPUT);
  pinMode(RIGHT_PIN_3, OUTPUT);
  
  while(EffectCnt == EFFECT_3)
  {
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_1, HIGH);    
    digitalWrite(LEFT_PIN_3, LOW);    
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_1, LOW);  
    digitalWrite(LEFT_PIN_3, HIGH);    
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
    pinMode(LEFT_PIN_1, INPUT);
    pinMode(RIGHT_PIN_1, INPUT);
    pinMode(LEFT_PIN_2, OUTPUT);
    pinMode(RIGHT_PIN_2, OUTPUT);
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_2, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);    
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_2, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
    pinMode(LEFT_PIN_3, INPUT);
    pinMode(RIGHT_PIN_3, INPUT);
    pinMode(LEFT_PIN_1, OUTPUT);
    pinMode(RIGHT_PIN_1, OUTPUT);
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_2, LOW);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_2, HIGH); //последняя пара
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_2, LOW);
    delay(ViewDelay);
    pinMode(LEFT_PIN_1, INPUT);
    pinMode(RIGHT_PIN_1, INPUT);
    pinMode(LEFT_PIN_3, OUTPUT);
    pinMode(RIGHT_PIN_3, OUTPUT);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_2, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);
    pinMode(LEFT_PIN_2, INPUT);
    pinMode(RIGHT_PIN_2, INPUT);
    pinMode(LEFT_PIN_1, OUTPUT);
    pinMode(RIGHT_PIN_1, OUTPUT);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_3, HIGH);
  }
}
//------------------------------------------------------
void Lashes_4()
{
  const uint16_t ViewDelay = 30;
  randomSeed(analogRead(0));
  
  while(EffectCnt == EFFECT_4)
  {
    uint8_t randNumber = random(0, 7);
    switch(randNumber)
    {
      case 0:
        digitalWrite(LEFT_PIN_1, HIGH);
        digitalWrite(LEFT_PIN_3, HIGH);
      break;

      case 1:
        digitalWrite(RIGHT_PIN_1, HIGH);
        digitalWrite(RIGHT_PIN_3, HIGH);
      break;

      case 2:
        digitalWrite(LEFT_PIN_1, HIGH);
        digitalWrite(LEFT_PIN_2, HIGH);
      break;

      case 3:
        digitalWrite(RIGHT_PIN_1, HIGH);
        digitalWrite(RIGHT_PIN_2, HIGH);
      break;

      case 4:
        digitalWrite(LEFT_PIN_2, HIGH);
        digitalWrite(LEFT_PIN_3, HIGH);
      break;

      case 5:
        digitalWrite(RIGHT_PIN_2, HIGH);
        digitalWrite(RIGHT_PIN_3, HIGH);
      break;
    }

    delay(ViewDelay);
    Lashes_Off();
  }
}
//------------------------------------------------------
void Lashes_5()
{
  const uint8_t DelayMin = 1;
  const uint8_t DelayMax = 25;
  const uint8_t LashesON = 6;
  int8_t DelayVal = DelayMin;
  bool Direction = false;
  
  while(EffectCnt == EFFECT_5)
  {
    for (uint8_t i = 0; i < LashesON; i++)
    {
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(DelayVal);
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);
    digitalWrite(RIGHT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(DelayVal);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(DelayVal);
    }

    if (!Direction)
    {
      DelayVal++;
      if (DelayVal == DelayMax + 1)
      {
        DelayVal = DelayMax - 1;
        Direction = true;
      }
    }
    else
    {
      DelayVal--;
      if (DelayVal == DelayMin - 1)
      {
        DelayVal = DelayMin + 1;
        Direction = false;
      }
    }
  }
}
//------------------------------------------------------
void Lashes_6()
{
  const uint16_t ViewDelay = 5;
  const uint8_t LashesON_RED = 45;
  const uint8_t LashesON_RED_BLUE = LashesON_RED;
  
  pinMode(LEFT_PIN_1, OUTPUT);
  pinMode(RIGHT_PIN_1, OUTPUT);
  pinMode(LEFT_PIN_2, INPUT);
  pinMode(RIGHT_PIN_2, INPUT);
  pinMode(LEFT_PIN_3, OUTPUT);
  pinMode(RIGHT_PIN_3, OUTPUT);

  for (uint8_t i = 0; i < LashesON_RED; i++)
  {
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
  }

  for (uint8_t i = 0; i < LashesON_RED_BLUE; i++)
  {
    pinMode(LEFT_PIN_1, OUTPUT);
    pinMode(RIGHT_PIN_1, OUTPUT);
    pinMode(LEFT_PIN_2, INPUT);
    pinMode(RIGHT_PIN_2, INPUT);
    pinMode(LEFT_PIN_3, OUTPUT);
    pinMode(RIGHT_PIN_3, OUTPUT);
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
    pinMode(LEFT_PIN_1, INPUT);
    pinMode(RIGHT_PIN_1, INPUT);
    pinMode(LEFT_PIN_2, OUTPUT);
    pinMode(RIGHT_PIN_2, OUTPUT);
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_2, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_2, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
  }

  pinMode(LEFT_PIN_1, OUTPUT);
  pinMode(RIGHT_PIN_1, OUTPUT);
  
  while(EffectCnt == EFFECT_6)
  {
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);
    digitalWrite(RIGHT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);
  }
}
//------------------------------------------------------
void Lashes_7()
{
  const uint16_t ViewDelay = 70;

  pinMode(LEFT_PIN_1, OUTPUT);
  pinMode(RIGHT_PIN_1, OUTPUT);
  pinMode(LEFT_PIN_2, INPUT);
  pinMode(RIGHT_PIN_3, INPUT);
  pinMode(LEFT_PIN_3, OUTPUT);
  pinMode(RIGHT_PIN_2, OUTPUT);
  
  while(EffectCnt == EFFECT_7)
  {
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);    
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_2, HIGH);
    delay(ViewDelay);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_3, HIGH);    
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_2, LOW);
    delay(ViewDelay);    
    pinMode(LEFT_PIN_1, INPUT);    
    pinMode(LEFT_PIN_2, OUTPUT);   
    digitalWrite(LEFT_PIN_2, HIGH);    
    digitalWrite(LEFT_PIN_3, LOW);
    pinMode(RIGHT_PIN_1, INPUT);
    pinMode(RIGHT_PIN_3, OUTPUT);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);    
    digitalWrite(LEFT_PIN_2, LOW);    
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);    
    pinMode(LEFT_PIN_3, INPUT);
    pinMode(RIGHT_PIN_2, INPUT);
    pinMode(LEFT_PIN_1, OUTPUT);
    pinMode(RIGHT_PIN_1, OUTPUT);
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);    
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_3, LOW); //последняя пара
    delay(ViewDelay);    
    digitalWrite(LEFT_PIN_1, HIGH);
    digitalWrite(RIGHT_PIN_1, LOW);
    digitalWrite(LEFT_PIN_2, LOW);
    digitalWrite(RIGHT_PIN_3, HIGH);
    delay(ViewDelay);    
    pinMode(LEFT_PIN_1, INPUT);
    pinMode(RIGHT_PIN_1, INPUT);
    pinMode(LEFT_PIN_3, OUTPUT);
    pinMode(RIGHT_PIN_2, OUTPUT);
    digitalWrite(LEFT_PIN_3, HIGH);
    digitalWrite(RIGHT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_3, LOW);
    delay(ViewDelay);    
    digitalWrite(LEFT_PIN_2, HIGH);
    digitalWrite(RIGHT_PIN_3, HIGH);
    digitalWrite(LEFT_PIN_3, LOW);
    digitalWrite(RIGHT_PIN_2, LOW);
    delay(ViewDelay);    
    pinMode(LEFT_PIN_2, INPUT);
    pinMode(RIGHT_PIN_3, INPUT);
    pinMode(LEFT_PIN_1, OUTPUT);
    pinMode(RIGHT_PIN_1, OUTPUT);
    digitalWrite(LEFT_PIN_1, LOW);
    digitalWrite(RIGHT_PIN_1, HIGH);
    digitalWrite(LEFT_PIN_3, HIGH);
  }
}
//----------------------------------------
void Key_ISR()
{
  EffectCnt++;
  if (EffectCnt > EFFECT_LAST)
    EffectCnt = EFFECT_0;

  PCintPort::detachInterrupt(KEY_PIN);
}
//----------------------------------------
void Lashes_Off()
{
  pinMode(LEFT_PIN_1, OUTPUT);
  pinMode(LEFT_PIN_2, OUTPUT);
  pinMode(LEFT_PIN_3, OUTPUT);
  pinMode(RIGHT_PIN_1, OUTPUT);
  pinMode(RIGHT_PIN_2, OUTPUT);
  pinMode(RIGHT_PIN_3, OUTPUT);
  digitalWrite(LEFT_PIN_1, LOW);
  digitalWrite(LEFT_PIN_2, LOW);
  digitalWrite(LEFT_PIN_3, LOW);
  digitalWrite(RIGHT_PIN_1, LOW);
  digitalWrite(RIGHT_PIN_2, LOW);
  digitalWrite(RIGHT_PIN_3, LOW);
}


Let's block ads! (Why?)

Комментариев нет:

Отправить комментарий