/******************************************************* Fabricademy 2023-2024 Week5 E-Textile Book *******************************************************/ #include #ifdef __AVR__ #include // Required for 16 MHz Adafruit Trinket #endif #define PIN 6 // NeoPixel #define NUMPIXELS 3// Number of NeoPixel Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); #define DELAYVAL 500 // Time (in milliseconds)?❓?? to pause between pixels const int btnM0Pin=3; //Cover page button const int btnM2Pin=4; //page button const int btnM3Pin=5; //page button const int sliderPin=0; //Cloud slider const int pullPin=1; //Cat pull sensor int mode=0; int cr,cg, cb; //rgb color int valM1, valM2, lastValM2, valM1L, valM1H, valM2L, valM2H ; //----touch ------- int f=0;// const int outPin = 8; //Arduino const int inPin = 9; //Arduino const int top=1500; // for Arduino IDE Serial plotter const int bottom=0; // for Arduino IDE Serial plotter //------------------------------------------------------------ // Setup //------------------------------------------------------------ void setup() { Serial.begin(9600); pinMode(btnM0Pin, INPUT_PULLUP); pinMode(btnM2Pin, INPUT_PULLUP); pinMode(btnM3Pin, INPUT_PULLUP); pinMode(sliderPin, INPUT); pinMode(pullPin, INPUT_PULLUP); pinMode(outPin,OUTPUT); // Touch: send pin pinMode(inPin,INPUT); //receive pin pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) pixels.clear(); // Set all pixel colors to 'off' mode=0; iniMode1(); iniMode2(); } //------------------------------------------------------------ // Loop //------------------------------------------------------------ void loop() { chkMode(); switch(mode){ case 0: mode0(); break; case 1: mode1(); break; case 2: mode2(); break; case 3: mode3(); break; } delay(100); } //------------------------------------------------------------ void chkMode(){ int a=readDdata(3,btnM0Pin); if(a==0){ mode=0 ; } /* if(digitalRead(btnM0Pin)){ if(digitalRead(btnM3Pin)){ mode=3; }else if(digitalRead(btnM2Pin)){ mode=2; }else{ mode=1; } }else{ mode=0; } */ } void mode0(){ pixels.clear(); // Set all pixel colors to 'off pixels.show(); int a=readDdata(3,btnM0Pin); Serial.println(a); if(a){ mode=1; } } void iniMode1(){ int a=readAdata(10,sliderPin); valM1L=a; valM1H=a; } void mode1(){ //pixels.clear(); // Set all pixel colors to 'off' int a=readAdata(10,sliderPin); // int a=analogRead(sliderPin); valM1=map(a,valM1L,valM1H,0,8); // valM1=map(a,770,900,0,8); if(a>valM1H){ valM1H=a;} if((700valM2H){ valM2H=a;} //if((10