home


The "synth fan a" uses LEDs to send frequencys to the LDRs and modulate these frequencys by fans that rotate inbetween them.

the SFa manual.

The synth fan small uses just the LDR and the fan to make sine wave like signals.

build on request: shop

 
// Synth Fan a 
// Gijs Gieskes june 2009
// Software version 16.

byte ledA = 9;
byte ledB = 10;
boolean pinstate = LOW;

//MIDI
byte setNoteOn = 0x90;
byte setNoteOff= 0x80;
byte addMidiNote = 2;

boolean but11 = false;

int ampA = 0;
byte ampAV = 0;
boolean ampUD = false;

byte volumeL1 = 0;

//analog read values
int av[] = {0,0,0,0};

//digitalread values
boolean But[] = {0,0,0,0};
byte buts[] = {4,5,6,7,8};

//sequencer
byte seq[3][257];
int seqCount = 1;
boolean stepMode = true;

byte FOrNoF[] = {0,0};

unsigned long timerA = 0;

//clocks
boolean clocksignals = false;

//trigger out
boolean triggerBool = LOW;
byte triggerPin = 2;
byte trigLedPin = 3;

unsigned long intervalTime = 7000;

unsigned int bins[] = {128, 64, 32, 16};

unsigned long anaV = 15208;

unsigned int freq[] = {4049, 4290, 4545, 4815, 5102, 5405, 5727, 6067, 6428, 6810, 7215, 7644};

void setup() 
{ 
  //speed up PWM on pin 9 and 10: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559
  TCCR1B = TCCR1B & 0b11111000 | 0x01;
  
  for(int i=0; i<257; i++){
    seq[0][i] = 255;
    seq[1][i] = 255;
    seq[2][i] = 255;
  }
  
  for(byte i=0; i<5; i++){ 
    pinMode(buts[i], INPUT);
    digitalWrite(buts[i], HIGH);
  }
  
  pinMode(ledA, OUTPUT);
  pinMode(ledB, OUTPUT);
  pinMode(triggerPin, OUTPUT);
  pinMode(trigLedPin, OUTPUT);
    
  Serial.begin(31250);
  delay(200);
} 

void loop() 
{ 
  
  if(micros() - timerA > intervalTime){
    timerA = micros();
    
    intervalTime = map(av[3], 0, 1023, 30000, 4000);
    
    //reading the potentiometers
    aread();
    //reading the buttons
    dread();
    //the sequencer
    seqRec();
    //change sequencer step mode
    changeSettings();
    
    midiNotes();
    
    anaV = freq[(seq[0][seqCount] & B00001111) - 4] / bins[(seq[0][seqCount] >> 4) - 12];
    
    FOrNoF[0] = seq[1][seqCount] & B00000001;
    FOrNoF[1] = seq[2][seqCount] & B00000001;
    
    //start stop sequence.
    StartStop();
    
    //trigger
    clocking();
    
  }
   
  if(clocksignals){
    static byte delayCounter = 0;
    delayCounter++;
  
    if(delayCounter > 31){
      delayCounter = 0;
    
      pinstate = !pinstate;
      if(pinstate && !FOrNoF[0]){
        analogWrite(ledA, 0);
      }else{
        analogWrite(ledA, ((seq[1][seqCount] >> 1) << 1));
      }
      if(pinstate && !FOrNoF[1]){
        analogWrite(ledB, 0);
      }else{
        analogWrite(ledB, ((seq[2][seqCount] >> 1) << 1));
      }
    }
  }else{
    analogWrite(ledA, 0);
    analogWrite(ledB, 0);
  }
  delayMicroseconds(anaV-16);
}

void midiNotes(){
  static byte lastNote = 0;
  static byte currNote = 0;
   
  currNote = ((7 - ((seq[0][seqCount] >> 4) - 11)) * 12) - ((seq[0][seqCount] & B00001111) - 4);
  
  currNote += 2 + addMidiNote;
  
  if(lastNote != currNote){
    sendMIDI(setNoteOff, lastNote, 0); 
    sendMIDI(setNoteOn, currNote, (seq[1][seqCount] >> 1)); 
    lastNote = currNote;
  }
}

//http://itp.nyu.edu/physcomp/Labs/MIDIOutput
void sendMIDI(char sb, char data1, char data2) {
  Serial.print(sb, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}

void StartStop(){
  static boolean SS = false;
  static boolean hold = false;

  if(But[0] == LOW){
    hold = true;
  }
  
  if(But[0] == HIGH){
    if(hold){
      SS = !SS;
      if(SS){
        //start sequence
        Serial.print(250, BYTE);
        clocksignals = true;
      }else{
        //stop sequence
        Serial.print(252, BYTE);
        clocksignals = false;
        //reset the sequencers counter..
        seqCount = 1;
      }
      hold = false;
    }
  }
}

void changeSettings(){
  if(But[0] == LOW && But[1] == LOW){
    stepMode = true;
  }else if(But[0] == LOW && But[2] == LOW){
    stepMode = false;
  }else if(But[0] == LOW && But[3] == LOW){
    addMidiNote = map(av[1], 0, 1023, 0, 3) * 12; //still needs correcting
  }
}

void clocking(){
  static byte clockCounter = 0;
  
  clockCounter++;
  
  if(clockCounter > 3){
    clockCounter = 0;
    
    //trigger signals
    if(clocksignals){
      triggerBool = !triggerBool;
      digitalWrite(trigLedPin, triggerBool);
      digitalWrite(triggerPin, triggerBool);
    }
    
    //midi clock
    Serial.print(248, BYTE);
    Serial.print(248, BYTE);
    Serial.print(248, BYTE);
  }
}

void seqRec(){

  if(clocksignals){
    seqCount++;
    if(stepMode){
      if(seqCount > map(av[0], 0, 1023, 1, 256)){
        seqCount = 1;
      }
    }else{
      if(seqCount > ((255 >> map(av[0], 0, 1023, 7, 0)) + 1)){
        seqCount = 1;
      }
    }
  }
  
  if(But[1] == HIGH && But[4] == HIGH){
    if(But[2] == LOW){ //record keyboard frequencys
      //octaves
      seq[0][seqCount] |= B11110000;
      seq[0][seqCount] &= ~(map(av[1], 0, 1023, 0, 3) << 4);
      //set firt bit in light seq LOW
      seq[1][seqCount] |= B00000001;
      seq[1][seqCount] &= B11111110;
    }
    if(But[3] == LOW){ //record keyboard frequencys
      //12 notes
      seq[0][seqCount] |= B00001111;
      seq[0][seqCount] &= ~map(av[2], 0, 1023, 0, 11);
      //set firt bit in light seq LOW
      seq[2][seqCount] |= B00000001;
      seq[2][seqCount] &= B11111110;
    }
  }else if(But[1] == LOW && But[4] == HIGH){
    if(But[2] == LOW){
      //volume A
      seq[1][seqCount] |= B11111110;  //hide light seq bit.
      seq[1][seqCount] &= ~(map(av[1], 0, 1023, 127, 0) << 1);  //shift 4 to left, inverse, merge.
    }
    if(But[3] == LOW){
      //volume B
      seq[2][seqCount] |= B11111110;  //hide light seq bit.
      seq[2][seqCount] &= ~(map(av[2], 0, 1023, 127, 0) << 1);
    }
  }else if(But[4] == LOW && But[1] == HIGH){
    if(But[2] == LOW){
      //set firts bit HIGH for light seq 
      seq[1][seqCount] |= B00000001;
      seq[1][seqCount] &= B11111111;
    }
    if(But[3] == LOW){
      //set firts bit HIGH for light seq 
      seq[2][seqCount] |= B00000001;
      seq[2][seqCount] &= B11111111;
    }
  }
}

void aread(){
  for(byte i=0; i<4; i++){
    av[i] = analogRead(i);
  }
}

void dread(){
  for(byte i=0; i<5; i++){
    But[i] = digitalRead(buts[i]);
  }
}


synth-fan-small
synth-fan-a

Copy "ilovegijs" here: (it stops spam bots)
Put your here:
1977 B.C. till 2010 © Gijs Gieskes - about