Jan Walraven
DevOps



Categories:
  • Arduino (2)
  • CSS (3)
  • Docker (10)
  • ESXi (1)
  • Git (4)
  • Javascript (6)
  • Linux (31)
  • Mac (6)
  • Magento (4)
  • Mysql (13)
  • PHP (9)
  • Zend framework 2 (9)
  • Posted on February 19, 2012

    In this project we created an Christmas tree with infrared detection.
    When someone passes by, the sensors detects movement and the Christmas tree begins to blink and plays Christmas songs.

    Needed

    • Arduino
    • Arduino waveshield
    • Infrared movement sensor
    • SD card
    • Christmas songs

    Setup

    Infrared Detection

    Code

    
    #include "kerstDetectie.h"
    #include 
    #include 
    #include "util.h"
    #include "wave.h"
     
    AF_Wave card;
    File f;
    Wavefile wave;      // only one!
     
    #define redled 9
     
    uint16_t samplerate;
     
    int inPin = 6;   // pushbutton connected to digital pin 7
    int val = 0;     // variable to store the read value
    int relay1Pin =7;//relay pin 1 to 7
    int relay2Pin =8;// relay pin to 8
    int ledPin = 11; // LED connected to digital pin 13
     
     
     
    void ls() {
      char name[13];
      int ret;
     
      card.reset_dir();
      putstring_nl("Files found:");
      while (1) {
        ret = card.get_next_name_in_dir(name);
        if (!ret) {
           card.reset_dir();
           return;
        }
        Serial.println(name);
      }
    }
     
     
    boolean playfile(char *name) {
       f = card.open_file(name);
       if (!f) {
          putstring_nl(" Couldn’t open file"); return false;
       }
       if (!wave.create(f)) {
         putstring_nl(" Not a valid WAV"); return false;
       }
       // ok time to play!
       wave.play();
       return true;
    }
    void playcomplete(char *name) {
      uint16_t potval;
      uint32_t newsamplerate;
     
      playfile(name);
      samplerate = wave.dwSamplesPerSec;
      while (wave.isplaying) {
            // you can do stuff here!
             //digitalWrite(ledPin,HIGH);
             digitalWrite(relay1Pin,HIGH);
             digitalWrite(relay2Pin,LOW);
             delay(50);
             //digitalWrite(ledPin,LOW);
             digitalWrite(relay2Pin,HIGH);
             digitalWrite(relay1Pin,LOW);
            delay(50);
     
       }
      digitalWrite(relay1Pin,HIGH);
      digitalWrite(relay2Pin,HIGH);
     
      putstring_nl("klaar met spelen");
      card.close_file(f);
    }
     
    //————————–
     
     
    void setup()
    {
      pinMode(ledPin, OUTPUT);
      pinMode(relay1Pin,OUTPUT);
      pinMode(relay2Pin,OUTPUT);
      pinMode(inPin, INPUT);
     
      pinMode(2, OUTPUT);
       pinMode(3, OUTPUT);
       pinMode(4, OUTPUT);
       pinMode(5, OUTPUT);
       pinMode(redled, OUTPUT);
     
      Serial.begin(9600);           // set up Serial library at 9600 bps
      Serial.println("Wave test!");
     
     
      if (!card.init_card()) {
     
        putstring_nl("Card init. failed!"); return;
      }
      if (!card.open_partition()) {
        putstring_nl("No partition!"); return;
      }
      if (!card.open_filesys()) {
        putstring_nl("Couldn’t open filesys"); return;
      }
     
     
     
      if (!card.open_rootdir()) {
        putstring_nl("Couldn’t open dir"); return;
      }
     
      putstring_nl("Files found:");
    //  ls();
     
      playcomplete("SHIP.WAV");
     
     
      digitalWrite(relay1Pin,HIGH);
      delay(500);
      digitalWrite(relay2Pin,HIGH);
      delay(1000);
      digitalWrite(relay1Pin,LOW);
      digitalWrite(relay2Pin,LOW);
      delay(500);
      digitalWrite(relay1Pin,HIGH);
      digitalWrite(relay2Pin,HIGH);
    }
    //————————-
     
    uint8_t tracknum = 0;
     
     
    void playSound(){
       uint8_t i, r;
       char c, name[15];
       String fileName;
     
       card.reset_dir();
       // scroll through the files in the directory
       for (i=0; i