#include #include #include #define PIN 6 // pin for neopixel #define NUMPIXELS 12 // Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); #define DELAYVAL 10 int x = 0; int Liquid_level = 0; int step_num = 0; int delta = 1; int color[] = {255, 255, 0}; int motorPin = 16; // pin that turns on the motor int watertime = 60; // how long to water in seconds int waittime = 1; // how long to wait in seconds SoftwareSerial Serial1(2, 3);//(Rx_UNO_to_Tx_mp3,Tx_UNO with 1k ohm) void setup() { //i2c Wire.begin(8); //MP3 Serial1.begin(9600); volume(0x1E);//Volume settings 0x00-0x1E //Neopixels //Motor pinMode(motorPin, OUTPUT); // set 16 to an output so we can use it to turn on the transistor pinMode(LED_BUILTIN, OUTPUT); Wire.onReceive(receiveEvent); Wire.onRequest(requestEvent); } void receiveEvent(int bytes) { // Interrupt Service Routine 割り込み x = Wire.read(); // read e from Master Serial.print("received -------------" ); Serial.println((char)x);// "1" is ASCII code 49 Liquid_level = 0;//empty } void requestEvent() { //ISR 割り込み Serial.println("REQUESTEvent"); if (Liquid_level == 1) { Wire.write("1", strlen("1")); Serial.print("sent Liquid_level = "); Serial.println(Liquid_level); } else Wire.write("0", strlen("0")); } void loop() { Serial.println("Loop"); //mp3 if (x == '2') { Serial.println("play dozodozo"); play(0x01);//Play the specified audio:0x01-file0001//en //Serial1.write(order,4);//order play delay(2000); x = '0'; } if (x == '3') { Serial.println("play dozodozo"); play(0x04);//Play the specified audio:0x01-file0001//jp //Serial1.write(order,4);//order play delay(2000); x = '0'; } if (x == '4') { Serial.println("play dozodozo"); play(0x03);//Play the specified audio:0x01-file0001//fr //Serial1.write(order,4);//order play delay(2000); x = '0'; } if (x == '1') { Serial.println("MOTOR ON"); pixels.begin(); for (int i = 0; i < pixels.numPixels(); i++) { // ストリップの長さに沿って色相環(65536の範囲)を1回転させる量だけピクセルの色相をオフセットします。 int pixelHue = step_num + (i * 65536L / pixels.numPixels()); // ColorHSV関数に色相(0 to 65535)を渡し、その結果をgamma32()でガンマ補正します。 pixels.setPixelColor(i, pixels.gamma32(pixels.ColorHSV(pixelHue))); } pixels.show(); step_num += 256; if (step_num == 65536) { step_num = 0; } Serial.println("play spring ocean"); play(0x02);//Play the specified audio:0x01-file0001//au[ //Serial1.write(order,4);//order play delay(2000); //Motor digitalWrite(motorPin, HIGH); // turn on the motor digitalWrite(LED_BUILTIN, HIGH); // turn on the LED delay(watertime * 1000); // 10seconds digitalWrite(motorPin, LOW); // turn off the motor digitalWrite(LED_BUILTIN, LOW); // turn off the LED delay(waittime * 1000); // 1 second /*Liquid_level = 1;//full Serial.print("Motor OFF: Liquid_level ="); Serial.println(Liquid_level); x = '0';*/ }//if delay(500); /*if (x == '9') { Serial.println("MOTOR OFF"); digitalWrite(motorPin, LOW); // turn off the motor digitalWrite(LED_BUILTIN, LOW); // turn off the LED delay(waittime * 1000); // multiply by 1000 to translate seconds to milliseconds }*/ } void play(unsigned char Track) { unsigned char play[6] = {0xAA, 0x07, 0x02, 0x00, Track, Track + 0xB3}; Serial1.write(play, 6);//(buf, len) } void volume( unsigned char vol) { unsigned char volume[5] = {0xAA, 0x13, 0x01, vol, vol + 0xBE}; Serial1.write(volume, 5); }