/************************************************************ * Fabricademy FP version4 * ************************************************************/ #include #include Ticker timer; // NeoPixel #include #define PIN D10// Neopixel pin //#define PIN D8// Neopixel pin #define NUMPIXELS 1 // Number of NeoPixels Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); //Speaker #define spPin D2// //int mScale[]={131,165,196,262,330,392,523,659,784,1047}; //C#3, E#3, G#3, --- //int mScale[]={277,311,329,391,440}; //C#4, D#4, E#4, G#4, A#4) int mScale[]={880,1046,1174,1318,1567,1760}; //A#4,C#5, D#5, E#5, G#5, A#5) int mScale2[]={2093,2349,2637,3135,3520}; //C#6, D#6, E#6, G#6, A#6) //BioMetal #define amPin1 D7// #define amPin2 D5// //#define amPin2 D4// //Touch int f=0;//フィルタ用変数 const int touchOutPin = D8; // const int touchInPin = D9; // //const int touchOutPin = D9; // //const int touchInPin = D10; // //int onVal=70; //bool touchOn=false; //Gas Sensor const int gasOutPin = D0; // const int gasInPin = A1; int gasVal = 0; //ADC data float sensor_r; //Mode int appMode=0; //unsigned long timCnt; //mills unsigned long lpCnt=0;; // int time1 = 90; int time2 = time1+30; int time3 = time2+10; //buffer int time4 = time3+10; int time5 = time4+1; bool isLED = true; int ledBr = 100; int br=4; //int counter=2000; void setup() { //NeoPixel setup pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) pixels.clear(); // Set all pixel colors to 'off' //Touch setup // pinMode(touchOutPin,OUTPUT); // send pin // pinMode(touchInPin,INPUT); //receive pin pinMode(amPin1,OUTPUT); // pinMode(amPin2,OUTPUT); // //Gas sensor setup pinMode(gasOutPin, OUTPUT); pinMode(gasInPin, INPUT); // Serial.begin(115200); Serial.begin(9600); // Serial.println("Setup completed"); timer.attach(1.0, intMain); // Interupt every 1sec } void loop() { // Serial.println("==== loopTest ===="); //----temp } void intMain(){ chkMode(); switch(appMode){ case 0: mode0(); break; case 1: mode1(); break; case 2: mode2(); break; case 3: mode3(); break; case 4: mode4(); break; } } void mode0(){ act1off(); act2off(); isLED = true; dspLed(0); //noTone(spPin); chkFerment(); //chkTouch(); } void mode1(){ dspLed(1); randomTone(); //chkTouch(); } void mode2(){ // buffer to stop tone noTone(spPin); dspLed(2); } void mode3(){ noTone(spPin); dspLed(2); chkAct1(); } void mode4(){ noTone(spPin); dspLed(3); chkAct2(); } void chkMode(){ if( lpCnt< time1){ appMode=0; }else if(lpCnt < time2){ appMode=1; }else if(lpCnt < time3){ appMode=2; }else if(lpCnt < time4){ appMode=3; }else if(lpCnt < time5){ appMode=4; }else{ appMode=0; act2off(); lpCnt=0; } lpCnt++; if( appMode !=0){ Serial.print(" lpCnt = "); Serial.println(lpCnt); } } void chkFerment(){ chkGas(); } void chkAct1(){ act2off(); analogWrite(amPin1, 200); Serial.println(" ******AM 1 ON"); } void act1off(){ analogWrite(amPin1, 0); } void act2off(){ analogWrite(amPin2, 0); } void chkAct2(){ act1off(); //isLED = false; analogWrite(amPin2, 180); Serial.println(" ******AM 2 ON"); } void dspLed(int ledMode){ if(isLED){ for (int i = 0; i < NUMPIXELS; i++) { // For each pixel... // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255 switch(ledMode){ case 0: pixels.setPixelColor(i, pixels.Color(105, ledBr, 255)); break; case 1: pixels.setPixelColor(i, pixels.Color(255, 105, ledBr)); break; case 2: pixels.setPixelColor(i, pixels.Color(ledBr, 255, 255)); break; case 3: pixels.setPixelColor(i, pixels.Color(ledBr, 255, 255)); break; } pixels.setBrightness(ledBr); pixels.show(); // Send the updated pixel colors to the hardware. } ledBr += br; if(ledBr<5){ br=4;} else if(ledBr >250){ br=-4;} //Serial.print("ledBr="); }else{ pixels.clear(); // Set all pixel colors to 'off' pixels.show(); } } void randomTone(){ // tone(spPin, mScale[random(sizeof(mScale)-1)], random(10,150)); // // if(!touchOn){ tone(spPin, mScale[random(sizeof(mScale)-1)], random(100,180)); // // }else{ // tone(spPin, mScale2[random(sizeof(mScale)-1)], random(30,60)); // // } } void chkGas(){ digitalWrite(gasOutPin, HIGH); //PULSE pin HIGH delay(1); //Wait until OUT stabilizes gasVal = analogRead(gasInPin); //ADC // Serial.println(gasVal); delay(1); // digitalWrite(gasOutPin, LOW); //PULSE pin HIGH if (gasVal != 0) { //((3.0 / (adval * 5.0 / 1024.0)) - 1)*10k ohm //sensor_r = 6144.0 / gasVal - 10; // for 5V sensor_r = ((3*1024/gasVal*3.3) -1) *10; // for 3.3V Serial.println(sensor_r, 1); } timer.attach(0.998, intMain); // Interupt every 1sec }