TEL. 070-5349-1100
〒619-0237 京都府相楽郡精華町光台8丁目
1 // 1/f LED 2 3 int value = 0; // variable to keep the actual value 4 int led1pin = 9; // light connected to digital pin 9 5 int led2pin = 10; // light connected to digital pin 10 6 int led3pin = 11; // light connected to digital pin 11 7 float x = 0.1; 8 float x1 = 0.1; 9 10 void setup() { 11 // put your setup code here, to run once: 12 } 13 14 void loop() { 15 // put your main code here, to run repeatedly: 16 value = chaos(); 17 analogWrite(led1pin, value); 18 delay(100); 19 value = chaos(); 20 analogWrite(led2pin, value); 21 delay(50); 22 value = chaos(); 23 analogWrite(led3pin, value); 24 delay(130); 25 } 26 27 int chaos(){ 28 // 1/f yuragi 29 x = x1; 30 if(x < 0.5){ 31 x = x +2 * x * x; 32 } 33 else{ 34 x = x - 2 * (1.0 - x) * (1.0 -x); 35 } 36 37 if(x < 0.08){ 38 x = (float)(random(10, 50))/256; 39 } 40 if(x > 0.995){ 41 x = (float)(random(128, 253))/256; 42 } 43 44 x1 = x; 45 x = x * 125; 46 47 return (unsigned int)x; 48 } |