HomeMadeGarbage
Published

Digital Windmill "Digindmill"

I made ​​a digital windmill "Digindmill" revolved by breath.

IntermediateFull instructions provided10 hours12,314

Things used in this project

Story

Read more

Schematics

Block Diagram

Code

Digindmill_03.ino

Arduino
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

const int analogInPin = A1;  
int sensorValue = 0;
int amp = 0;
int rotDelay = 500;

int fin = 0;

//LED setting for 8 feathers of a windmill
#define NUMPIXELS      5
Adafruit_NeoPixel pixel0 = Adafruit_NeoPixel(NUMPIXELS, 2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixel1 = Adafruit_NeoPixel(NUMPIXELS, 3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixel2 = Adafruit_NeoPixel(NUMPIXELS, 4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixel3 = Adafruit_NeoPixel(NUMPIXELS, 5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixel4 = Adafruit_NeoPixel(NUMPIXELS, 6, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixel5 = Adafruit_NeoPixel(NUMPIXELS, 7, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixel6 = Adafruit_NeoPixel(NUMPIXELS, 8, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixel7 = Adafruit_NeoPixel(NUMPIXELS, 9, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel pixels[8] = {pixel0, pixel1, pixel2, pixel3, pixel4, pixel5, pixel6, pixel7};


uint32_t finColors[8];


void setup() {
  Serial.begin(9600);

  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  for(int i = 0; i < 8; i++ ){
    pixels[i].begin();
    pixels[i].setBrightness(20);
  }

  //color setting
  finColors[0] = pixels[0].Color(255,0,0);
  finColors[1] = pixels[0].Color(150,150,150);
  finColors[2] = pixels[0].Color(85,0,170);
  finColors[3] = pixels[0].Color(120,155,0);
  finColors[4] = pixels[0].Color(0,0,255);
  finColors[5] = pixels[0].Color(170,0,85);
  finColors[6] = pixels[0].Color(0,255,0);
  finColors[7] = pixels[0].Color(0,170,170);
}

void loop() {
  //Averaging of mic out
  for(int i = 0; i < 10; i++){
    sensorValue =+ analogRead(analogInPin);
  }
  Serial.print(sensorValue/10);
  
  //Bias elimination of mic out
  amp = abs(sensorValue/10 - 30);
  Serial.print(" ");
  Serial.print(amp);
  
  //Rotational speed derivation from mic out
  rotDelay = map(amp, 10, 60, 150, 0);
  if(rotDelay < 0){
    rotDelay = 0;
  }
  Serial.print(" ");
  Serial.println(rotDelay);
  
  for(int j = 0; j < 8; j++){
    int k = j + fin;
    if(k >= 8){
      k = k - 8;
    }
    for (int i = 0; i < 5; i++){
      pixels[j].setPixelColor(i, finColors[k]);
    }
  }
    
  for(int i = 0; i < 8; i++ ){
    pixels[i].show();
  }
  delay(15);

  //Windmill rotation
  if(amp > 10){
    delay(rotDelay);
    fin++;
    if(fin >= 8){
      fin = fin - 8;
    }
  }
  
  for(int i = 0; i < 8; i++ ){
    pixels[i].clear();
    pixels[i].show();
  }
  delay(1);
}

Credits

HomeMadeGarbage

HomeMadeGarbage

56 projects • 285 followers
We are family. hobby is D.I.Y!!

Comments