Ralph de Ruijter
Published © GPL3+

Cylon Pumpkin

A Cylon Pumpkin with Arduino Nano.

BeginnerFull instructions provided4 hours1,340
Cylon Pumpkin

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×10
5 mm LED: Red
5 mm LED: Red
×10
Resistor 330 ohm
Resistor 330 ohm
×10
Jumper wires (generic)
Jumper wires (generic)
×10

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Code

Cylon Visor

C/C++
Upload to your Arduino Nano V3 using Arduino IDE
int startPin = 2;
int activePin = 2;  //center of the active lights
int speed = 100;    //speed in ms, lower is faster
int direction = 1;  //visor direction
int width = 3;      //width of the active lights
int length = 10;    //amount of leds

int testPin = 6;

// the setup function runs once when you press reset or power the board
void setup()
{
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

  Serial.begin(115200);
}

void toggleOther(int activePin)
{

  for (int i = startPin; i < length + startPin; i++)
  {
    if (i != activePin)
    {
      digitalWrite(i, LOW);
    }
  }
}

void drawVisor(int activePin, int direction)
{

  for (int i = 0; i < width; i++)
  {
    if (direction == 1 && activePin < length + startPin || direction == -1 && activePin >= 0)
    {
      int pin = activePin + i * direction;
      digitalWrite(pin, HIGH);
      Serial.println(pin);
    }
  }
}

// the loop function runs over and over again forever
void loop()
{
  if (direction == 1 && activePin <= length + 1 || direction == -1 && activePin >= startPin)
  {
    toggleOther(activePin);
    drawVisor(activePin, direction);   
    delay(speed);

    activePin = activePin + direction;
  }

  //toggle direction
  if (activePin == length + 2 || activePin == 1)
  {
    direction = direction * -1;   
  }
}

Credits

Ralph de Ruijter

Ralph de Ruijter

1 project • 0 followers

Comments