Interactive window

From base48
Revision as of 16:54, 7 October 2012 by imported>Hyna (link)

Banik pičo

http://vimeo.com/8196236


Text


<syntaxhighlight lang="c"> int vetrak = 9; int adc_senzor = 0; float senzor = 0.0; int pwm = 0;


int eliminace_okoli = 30; // random sracky se senzoru

float minimal_pwm = 160; // pro kazdy vetrak jiny!

void setup() {

 // put your setup code here, to run once:
 Serial.begin(9600);

}

void loop() {

 // put your main code here, to run repeatedly: 
 adc_senzor = analogRead(A0);
 //senzor da max 3.2V, tzn prepocitat na plnej rozsah.
 // 5/3.2 = 1.5635

// 3.2V pode datasheetu, coz neni zas tak uplne pravdal. Proto to je jen 1.30

 if (adc_senzor*1.30 > 1023) {
     senzor = 1023;
     Serial.println("preteceni u senzor");
 } else {
   senzor = adc_senzor*1.30;
   
 }
   pwm = senzor/4; // ADC je do 1024, ale PWM jen do 256
   
   if (pwm < eliminace_okoli) {
     pwm = 0; // pri takto nizkych hodnotach povazujeme ze pred vylohou nikdo nestoji
   }
   
   if (pwm > 254) {
     Serial.println("preteceni u pwm"); // kdyby neco, tak nic
   } 
   
   //analogWrite(9, pwm);
 
 /* 
 zjsiteni kolik potrebuje vetrak na roztoceni
 for (int i=0; i <= 250; i=i+10){
     Serial.println(i); 
     analogWrite(9, i);
     delay(1000);
  } 
*/  
 
//  Serial.println(pwm);
 //delay(1000);
  analogWrite(9, pwm);
 

} </syntaxhighlight>