/*************************************************************************** Dr.Duino Inventor Edition Sketch www.DrDuino.com This sketch will perform a bunch of automated tests to help you confirm that your brand spanking new Dr.Duino Inventor shield is working! It was designed to walk you through every part of the hardware. Anytime you use your Inventor, you should run this test first to make sure everything is working and baseline your hardware. Make sure all jumpers are in the Monitor To Out (M-O) before starting. After uploading this sketch to your Arduino Uno or compatible board, open serial monitor (Tools/Serial Monitor). - THIS IS IMPORTANT - After you open serial monitor, on the bottom right hand corner are three drop down menus. Change the left most drop down to say "No Line Ending". Then, change the baud rate to 115200. If you do not, this sketch will not run. If you run into issues, please contact via our website using the help button on the bottom right of the screen. Note Arduino is a trademark of Arduino AG. Dr.Duino is not affiliated or endorsed by Arduino AG All code is provided as is without warranty of any kind either expressed or implied. Please visit www.DrDuino.com/TOS for our complete terms of service. ***************************************************************************/ //-----------------Calling libraries needed to run-----------// #include #include #include #include #include #include #include #include //-----------------Defines needed for FAST LED library to run-----// #define LED_TYPE WS2811 #define COLOR_ORDER GRB #define LED_PIN 25 // Your Dr.Duino Inventor Is wired to pin 25. #define NUM_LEDS 16 // Your Dr.Duino Inventor has 16 LED's if you want more, change this. Just make sure you use external power (Refer To the Manual for details). #define BRIGHTNESS 64 // Just a startup brightness, you can change this. 0-255 but be careful making WHITE at 255, you could damage your addressable LED's and/or Inventor shield. //------------------Object Instantiation-----------// DrDuino_Inventor Inventor; Stepper StepperMotor(Inventor.NumStepsTo360Degrees, Inventor.Mot1, Inventor.Mot3, Inventor.Mot2, Inventor.Mot4); DHT dht(Inventor.DHT11_Sensor, DHT11); HardwareSerial hwSerial(1); DFRobotDFPlayerMini MP3Player; CRGB leds[NUM_LEDS]; Adafruit_SSD1306 display(Inventor.OledWidth, Inventor.OledHeight, &Wire, -1); //------------------Generic Variable Declarations. Please do not change these-----------// boolean AllSwitchesWork = false; boolean AllPotsWork = false; boolean AllDiscretesWork = false; boolean DelayNeeded = false; boolean LDR_Works = false; boolean MessagePrinted = false; int TestNumber = 0; int SwitchResults[3] = {0, 0, 0}; int PotResults[3] = {0, 0, 0}; int LDR_InitialValue = 0; bool InventorTestsPassed = true; String UserTyped = ""; String FwVersion ="2.0.0"; //Everything in Setup gets called once, only at powerup void setup() { Serial.begin(115200); Inventor.begin(); delay(5000); dht.begin(); hwSerial.begin(9600, SERIAL_8N1, Inventor.MP3RX, Inventor.MP3TX); // speed, type, TX, RX if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32 Serial.println(F("OLED Not Found!!")); Serial.println(F("Verify JP22 & JP23 are set correctly for type A or Type B OLED.")); Serial.println(F("Verify Oled is plugged into J3 correctly.")); Serial.println(F("If soldered in, verify solder joints.")); for(;;); // Don't proceed, loop forever } DrduinoSplashScreen(); FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.setBrightness(BRIGHTNESS); FastLED.clear(true); ClearSerialMonitorScreen(false); Serial.println("-----Welcome To Your Dr.Duino Inventor Edition-----"); Serial.print(F("Firmware Version ")); Serial.println(FwVersion); Serial.print(F("Library Version: ")); Serial.println(Inventor.GetInventorLibVersion()); Serial.print('\n'); Serial.println("Make sure all jumpers are in M-O position before starting."); Serial.println(F("Are you ready to begin?")); PressYorN(); } void loop() { ESP32SerialRead(); // Poll the UART for data. // This switch case is the meat and potatoes of what this entire sketch is doing. // It's reffered to as a state machine which will only continue on if the previous // test has passed. // You may also hear this reffered to as a round robin loop because, all it ever // does is go round and round in a loop forever! switch (TestNumber) { //--Waiting for user to start tests, by typing y--// case 0: if(UserTyped== "YES") { TestNumber++; UserTyped= ""; } break; //--Start RED LED tests--// case 1: { if (MessagePrinted == false) { ClearSerialMonitorScreen(false); DisplayMessage2User("Red LED Tests",1); digitalWrite(Inventor.LED1, HIGH); delay(250); digitalWrite(Inventor.LED2, HIGH); delay(250); digitalWrite(Inventor.LED3, HIGH); delay(250); Serial.println(F("Is LED1, LED2 & LED3 on? (Top left of board)")); PressYorN(); MessagePrinted = true; } if(UserTyped== "YES") { digitalWrite(Inventor.LED1, LOW); delay(250); digitalWrite(Inventor.LED2, LOW); delay(250); digitalWrite(Inventor.LED3, LOW); delay(250); ClearSerialMonitorScreen(false); Serial.println(F("Great, RED LED's are working")); DisplayMessage2User("LEDs Passed!",1); TestNumber++; MessagePrinted = false; UserTyped= ""; } else if (UserTyped == "NO") { TroubleShoot(TestNumber); } } break; //--Start Pushbutton tests--// case 2: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); Serial.println(F("//-----------Push button Tests---------// ")); Serial.println(F("Press SW1, then SW2 and finally SW3. (Top Right of board)")); Serial.println(F("Have you pressed all the Switches?")); DisplayMessage2User("Button Tests",1); PressYorN(); MessagePrinted= true; } SwitchTests(); if((SwitchResults[0]==1) && (SwitchResults[1]==1) && (SwitchResults[2]==1)) { ClearSerialMonitorScreen(false); Serial.println(F("Switch tests passed!")); DisplayMessage2User("Switches Passed!",1); TestNumber++; MessagePrinted = false; UserTyped= ""; } else if (UserTyped == "YES") { TroubleShoot(TestNumber); } break; //--Start Potentiometer tests Part 1--// case 3: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); Serial.println(F("//-----------Potentiometer Tests, Part 1---------// ")); Serial.println(F("Turn Pot1, Pot2 & Pot3 fully COUNTERCLOCKWISE.")); Serial.println(F("Don't force it once it stops.")); Serial.println(F("Are all pots turned fully counterclockwise?")); DisplayMessage2User("Potentiometer test 1!",1); PressYorN(); MessagePrinted = true; } PotTestsToZero(); if((PotResults[0]==1) && (PotResults[1]==1) && (PotResults[2]==1)) { delay(250);// Allow user to see last message on screen. AllPotsWork =false; PotResults[0]=0; PotResults[1]=0; PotResults[2]=0; ClearSerialMonitorScreen(false); Serial.println(F("Pot 0V tests passed!")); DisplayMessage2User("Pot test 1 Passed!",1); TestNumber++; MessagePrinted = false; UserTyped= ""; } if (UserTyped == "YES") { TroubleShoot(TestNumber); } break; //--Start Potentiometer tests Part 2--// case 4: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); Serial.println(F("//----Potentiometer Tests, Part 2---// ")); Serial.println(F("Now turn Pot1, Pot2 & Pot3 Fully CLOCKWISE.")); Serial.println(F("Don't force it once it stops.")); Serial.println(F("Are all pots turned fully clockwise?")); DisplayMessage2User("Potentiometer test 2!",1); PressYorN(); MessagePrinted = true; } PotTestsToFullScale(); if((PotResults[0]==1) && (PotResults[1]==1) && (PotResults[2]==1)) { AllPotsWork=true; delay(250);// allow user to see last message on screen. ClearSerialMonitorScreen(false); Serial.println(F("Pot high tests passed!")); DisplayMessage2User("Pot test 2 Passed!",1); TestNumber++; UserTyped= ""; MessagePrinted = false; } if (UserTyped == "YES") { TroubleShoot(TestNumber); } break; //--Start Light Sensor tests Part 1--// case 5: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); Serial.println(F("//-----------LDR Test Part 1---------// ")); Serial.println(F("Cover the LDR with your hand.")); Serial.println(F("You are trying to get a value less than 900.")); Serial.println(F("Look at the OLED for the current value.")); Serial.println(F("Are you covering it?")); DisplayMessage2User("LDR test 1",1); PressYorN(); MessagePrinted = true; } LDR_Covered(); if(LDR_Works == true) { ClearSerialMonitorScreen(false); Serial.println(F("LDR low light tests passed!")); DisplayMessage2User("LDR Low Passed!",1); TestNumber++; UserTyped= ""; MessagePrinted = false; LDR_Works=false; } if (UserTyped == "YES") { TroubleShoot(TestNumber); } break; //--Start Light Sensor tests Part 2--// case 6: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); Serial.println(F("//-----------LDR Tests Part 2---------// ")); Serial.println(F("Shine the flashlight from a cell onto the LDR.")); Serial.println(F("You are trying to get a value greater than 3900.")); Serial.println(F("Look at the OLED for the current value.")); Serial.println(F("Are you shinning a light on the it? ")); DisplayMessage2User("LDR test 2",1); PressYorN(); MessagePrinted = true; } LDR_FullLight(); if(LDR_Works == true) { ClearSerialMonitorScreen(false); Serial.println(F("LDR high brightness tests passed! ")); DisplayMessage2User("LDR high Passed!",1); TestNumber++; UserTyped= ""; MessagePrinted = false; } if (UserTyped == "YES") { TroubleShoot(TestNumber); } break; //--MP3 Player Test-// case 7: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); DisplayMessage2User("MP3 test",1); setupMP3Player(); Serial.println(F("//-----------MP3 Tests---------// ")); Serial.println(F("In 5 seconds from now, you should hear a messagge coming from the MP3 player. ")); delay(5000); MP3Player.play(4); Serial.println(F("Did you hear anything?")); PressYorN(); MessagePrinted = true; } if (UserTyped == "NO") { TroubleShoot(TestNumber); } else if (UserTyped == "YES") { ClearSerialMonitorScreen(false); Serial.println(F("MP3 Player is Working! ")); DisplayMessage2User("MP3 Player Passed!",1); TestNumber++; UserTyped= ""; MessagePrinted = false; } break; //--Start DHT Tests-// case 8: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); DisplayMessage2User("DHT 11 test",1); GetDHT11Data(); Serial.println(F("//----DHT 11 Tests---// ")); Serial.println(F("Do you see temperature data on the OLED?")); PressYorN(); MessagePrinted = true; } if(UserTyped== "YES") { ClearSerialMonitorScreen(false); Serial.println(F("Awesome, your DHT11 works!")); DisplayMessage2User("DHT11 Passed!",1); TestNumber++; UserTyped= ""; MessagePrinted = false; } else if (UserTyped == "NO") { TroubleShoot(TestNumber); } break; //--Start Relay Tests-// case 9: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); Serial.println(F("In one second, you should hear the relay clicking?")); DisplayMessage2User("Relay test",1); delay(1000); ToggleRelay(); Serial.println(F("Did you hear the the relay clicking?")); PressYorN(); MessagePrinted = true; } if(UserTyped== "YES") { ClearSerialMonitorScreen(false); Serial.println(F("Your Relay works!!!")); DisplayMessage2User("Relay Passed!",1); TestNumber++; UserTyped= ""; MessagePrinted = false; } else if (UserTyped == "NO") { TroubleShoot(TestNumber); } break; //--Stepper Motor Test-// case 10: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); Serial.println(F("------Stepper Motors TESTS------")); Serial.println(F("In 5 seconds from now, the motor should start moving.")); Serial.println(F("It will rotate 360 degrees in one direction,")); Serial.println(F("then 360 degrees in the opposite direction.")); Serial.println(F("Please look at the motor now.")); delay(5000); ControlStepperMotor(); Serial.println(F("Did the motor perfrom as described ?")); PressYorN(); DisplayMessage2User("Motor test",1); MessagePrinted = true; } if(UserTyped== "YES") { Serial.println(F("Perfect, your stepper motor and driver works!")); DisplayMessage2User("Stepper Motor Passed!",1); ClearSerialMonitorScreen(false); TestNumber++; UserTyped= ""; MessagePrinted = false; } else if (UserTyped == "NO") { TroubleShoot(TestNumber); } break; //--Addressable LED Tests-// case 11: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); Serial.println(F("//-----------Addressable LED Tests---------// ")); Serial.println(F("RGB LED tests are next.")); Serial.println(F("Shield your eyes a bit, these are BRIGHT!")); Serial.println(F("In Just a 3 second from now,")); Serial.println(F("the leds in the bottom right will come on.")); DisplayMessage2User("RGB LED test",1); delay(3000); PertyColors(10); Serial.println(F("Did you see lots of perty colors?")); FastLED.clear(true); PressYorN(); MessagePrinted = true; } if(UserTyped== "YES") { ClearSerialMonitorScreen(false); Serial.println(F("Great, you've got lights!")); DisplayMessage2User("RGB LEDs Passed!",1); TestNumber++; UserTyped= ""; MessagePrinted = false; } else if (UserTyped == "NO") { TroubleShoot(TestNumber); } break; //--Overall Pass Fail Results-// case 12: if (MessagePrinted == false) { ClearSerialMonitorScreen(true); if (InventorTestsPassed == true) { Serial.println(F("PASSED! CONGRATULATIONS your Dr.Duino Inventor Is Ready For Use!")); Serial.println(F("Depending on what package you purhcased, more Demo projects")); Serial.println(F("can be found when you go to File/Examples/DrDuino_Inventor/")); DisplayMessage2User("Dr.Duino Inventor PASSED!",1); DisplayMessage2User("Inventor PASSED!",1); MessagePrinted = true; } else if (InventorTestsPassed == false) { Serial.println(F("FAILED-Please correct all issues listed during testing & retest.")); Serial.println(F("Scroll up in this window to revisit the failed tests.")); DisplayMessage2User("Hardware Failed! Fix issues and retest your hardware.",1); MessagePrinted = true; } } break; default: //Serial.printlnln("Defaults Case"); break; } } /*************************************************************************** *---------------setupMP3Player Function----------------------- * This is how you initialize the MP3 player. * Special note here, most code you'll find on the internet starts the MP3 Player like this * if (!MP3Player.begin(hwSerial)) * * However, this only works correctly if the unit has never been "started before". * if you do not cycle power evertime, this usage can give odd behaviour. * * So by stuffing the argument as follows, you are forcing a reset every time * if (!MP3Player.begin(hwSerial,false,true)) // note, * the TRUE allows the MP3 player to restart if it was already powered on. * The False, is for turning on ACK's in the library. * USAGE * setupMP3Player();// * ***************************************************************************/ void setupMP3Player() { delay(250); if (!MP3Player.begin(hwSerial)) { Serial.println(F("Resetting MP3 Player")); // Try again, just incase the MP3 player was already on, and needs to be reset. if (!MP3Player.begin(hwSerial,false,true)) // note, while you don't need the false and true in this call, the TRUE allows the MP3 player to restart if it was already powered on. { Serial.println(F("MP3 Player Not found:")); Serial.println(F("1.Please recheck the orientation of the module.")); Serial.println(F("2.Please insert an SD card!")); DisplayMessage2User("MP3 Player Not Found!",1); } else { Serial.println(F("MP3 Player Restarted!")); DisplayMessage2User("MP3 Player Restarted!",1); MP3Player.volume(25); //Setting startup volume level 0-30 min max range. } } else { Serial.println(F("MP3 Player Online!")); DisplayMessage2User("MP3 Player Online!",1); MP3Player.volume(25); //Setting startup volume level 0-30 min max range. } } /*************************************************************************** *---------------ToggleRelay Function----------------------- * Used to turn the relay on and off 5 times. * * USAGE * ToggleRelay();// * ***************************************************************************/ void ToggleRelay() { for (int i = 0; i<5; i++) { digitalWrite(Inventor.RelayPin, LOW); delay(250); digitalWrite(Inventor.RelayPin, HIGH); delay(250); } } /*************************************************************************** *---------------ControlStepperMotor Function----------------------- * Used to demonstrate how to make the stepper motor take one 360 degree * revolution clockwise and 360 degrees Counter clockwise. * * USAGE * ControlStepperMotor();// * ***************************************************************************/ void ControlStepperMotor() { StepperMotor.setSpeed(10); // step one revolution in one direction: Serial.println("Spinning clockwise now..."); DisplayMessage2User("Turning Stepper CCW, please wait...",1); StepperMotor.step(Inventor.NumStepsTo360Degrees); digitalWrite(Inventor.Mot1, LOW); digitalWrite(Inventor.Mot2, LOW); digitalWrite(Inventor.Mot3, LOW); digitalWrite(Inventor.Mot4, LOW); delay(250); // step one revolution in the other direction: Serial.println("Spinning counterclockwise now..."); DisplayMessage2User("Turning Stepper CW, please wait...",1); StepperMotor.step(-Inventor.NumStepsTo360Degrees); delay(250); //--- The following lines of code, just makes it so that the stepper driver is all off after rotating.// digitalWrite(Inventor.Mot1, LOW); digitalWrite(Inventor.Mot2, LOW); digitalWrite(Inventor.Mot3, LOW); digitalWrite(Inventor.Mot4, LOW); } /*************************************************************************** *---------------GetDHT11Data Function----------------------- * Used to poll data from DHT11 sensor. * Temperature & Heat index is obtained in both degrees F & C. * Humidity is also polled. * Data is sent to the OLED and also the serial monitor. * * USAGE * GetDHT11Data();// * ***************************************************************************/ void GetDHT11Data() { float humidity = dht.readHumidity();// Get humidity. float temperature = dht.readTemperature();// Get temp in celsius. float Fahrenheit = dht.readTemperature(true); // Get readout of temp in degree's F. if (isnan(humidity) || isnan(temperature) || isnan(Fahrenheit)) // Precheck all data. { Serial.println(F("Failed to read from DHT sensor!")); display.clearDisplay(); display.setCursor(0, 0); display.setTextSize(1); display.println("DHT11 Sensor Not "); display.print("Found. Check wiring!"); display.display(); return; } float hif = dht.computeHeatIndex(Fahrenheit, humidity);// Calculate Heat index in degrees F. float hic = dht.computeHeatIndex(temperature, humidity, false);// Calculate Heat index in degrees C. // Post data to Serial monitor Serial.print(F("Humidity: ")); Serial.print(humidity); Serial.print(F("% Temperature: ")); Serial.print(temperature); Serial.print(F("°C ")); Serial.print(Fahrenheit); Serial.print(F("°F Heat index: ")); Serial.print(hic); Serial.print(F("°C ")); Serial.print(hif); Serial.println(F("°F")); // Post data to OLED. display.clearDisplay(); display.setCursor(0, 0); display.setTextSize(1); display.print("Humidity: "); display.print(humidity); display.println("%"); display.print("Temp: "); display.print(temperature); display.print(" C,"); display.print(Fahrenheit); display.println((" F")); display.print(("Heat Index: ")); display.print(hic); display.println(F("C ")); display.print(hif); display.println(F("F")); display.display(); } void DisplayMessageAndData(char Message[], int Data) { display.clearDisplay(); display.setCursor(0, 0); display.setTextSize(1); display.println(Message); display.println(Data); display.display(); } void DisplayPotData2User(int PotVal1,int PotVal2, int PotVal3) { display.clearDisplay(); display.setCursor(0, 0); display.setTextSize(1); display.print("Pot Value 1: "); display.println(PotVal1); display.print("Pot Value 2: "); display.println(PotVal2); display.print("Pot Value 3: "); display.println(PotVal3); display.display(); } void DisplayMessage2User(char Message[], int fontsize) { display.clearDisplay(); display.setCursor(0, 0); display.setTextSize(fontsize); display.println((Message)); display.display(); } void DrduinoSplashScreen() { display.clearDisplay(); display.setTextSize(2); // Normal 1:1 pixel scale display.setTextColor(WHITE); // Draw white text display.setCursor(10, 0); // Start at top-left corner display.cp437(true); // Use full 256 char 'Code Page 437' font display.println(("DR.DUINO")); display.setTextSize(1); display.setCursor(10, 15); // Start at top-left corner display.println(("Inventor Edition")); display.print((" Ver:")); display.println(( FwVersion)); display.display(); delay(100); } void PressYorN() { Serial.println(F("Please type y for yes, n for no, then press ENTER")); } /*************************************************************************** *---------------ClearSerialMonitorScreen Function----------------------- * Used to push any messages currently being displayed in the serial * monitor to the top. Creating a "blank" screen by pushing data on the screen * up by 100 lines. * * USAGE * ClearSerialMonitorScreen(True);// delay for 2.5 Seconds before pushing the screen clean. * ClearSerialMonitorScreen(True);// No delay,just push the screen clean. * ***************************************************************************/ void ClearSerialMonitorScreen(boolean delayneeded) { if (delayneeded == true) { delay(2500); } for (int cleardata = 0; cleardata<25; cleardata++) { Serial.println(); } } /*************************************************************************** *---------------ESP32SerialRead Function----------------------- * ***************************************************************************/ void ESP32SerialRead() { while (Serial.available()) { String DataRx = Serial.readString(); if ((DataRx == "y")||(DataRx == "Y")) { UserTyped = "YES"; } else if ((DataRx == "n")||(DataRx == "N")) { UserTyped = "NO"; } else if ((DataRx == "1")) { digitalWrite(Inventor.LED1, !digitalRead(Inventor.LED1)); UserTyped = "YES"; } else { Serial.flush(); UserTyped =" "; DataRx = " "; } } } /*************************************************************************** * ---------------PertyColors Function----------------------- * This creates a nice rotating color spectrum on your addressable LED's. * * USAGE * PertyColors(10);// wait upto 10ms inbetween changing colors. * ***********************************************************************/ void PertyColors(int wait) { uint8_t brightness = 255; for (int colorIndex1 =0; colorIndex1 <255; colorIndex1++) { for( int i = 0; i < NUM_LEDS; ++i) { leds[i] = ColorFromPalette( RainbowColors_p, colorIndex1, brightness, LINEARBLEND); } FastLED.show(); FastLED.delay(wait);// reccomend a value from 1(Fast) to 100 slowest } } /*************************************************************************** *---------------LDR_FullLight Function----------------------- * This function is looking for the voltage value that the LDR (on board Lightsensor) * is feeding back to the Arduino Uno. * * For this test, we want to see that the value is higher than 3900 out of 4095 * total bits. Note* the esp32 is a 12 bit A/D which is equal to 4095 (2^12). * So if a bright light is being shined directly on the sensor, it should easily * see over 3900. * USAGE * LDR_FullLight();// Read back what the LDR sees * ***************************************************************************/ void LDR_FullLight() { int Current_AnalogReading =0; int DifferenceInLight =0; Current_AnalogReading = Inventor.LDR_Average(); DisplayMessageAndData("High LDR Value: ", Current_AnalogReading); //Serial.println(Current_AnalogReading);// This line of code can be uncommented if you want to see the value. // You will see just a bunch of numbers wizzing past in the serial monitor. // As you increase the brightness, the value will also increase. // Recommend that you do not leave this uncommented. // Determine if the the LDR is seeing a change close or higher than 3900. // The resolution on the ESP's A/D is 4095 so if a bright light is detected // it will easily hit 3900. if (Current_AnalogReading >= 3900) { LDR_Works = true; } } /*************************************************************************** *---------------LDR_Covered Function----------------------- * This function is looking for the voltage value that the LDR (on board Lightsensor) * is feeding back to the Arduino Uno. * * For this test, we want to see that the value is lower than 500 out of 4095 * total bits. Note* the esp32 is a 12 bit A/D which is equal to 4095 (2^12). * So if the LDR is being covered, it should easily see a value lower than 900. * USAGE * LDR_Covered();// Read back what the LDR sees * ***************************************************************************/ void LDR_Covered() { int Current_AnalogReading =0; int DifferenceInLight =0; Current_AnalogReading = Inventor.LDR_Average(); DisplayMessageAndData("Low LDR Value : ", Current_AnalogReading); //Serial.println(Current_AnalogReading);// This line of code can be uncommented if you want to see the value. // You will see just a bunch of numbers wizzing past in the serial monitor. // As you increase the brightness, the value will also increase. // Recommend that you do not leave this uncommented. // Determine if the the LDR is seeing a change close or higher than 3900. // The resolution on the ESP's A/D is 4095 so if the LDR is being covered // it should easily register a value lower than 900. if (Current_AnalogReading <= 900) { LDR_Works = true; } } void PotTestsToFullScale() { int AnalogReading1, AnalogReading2,AnalogReading3; AnalogReading1=0; AnalogReading2=0; AnalogReading3=0; AnalogReading1 = analogRead(Inventor.Pot1); if(AnalogReading1 >=4095) { PotResults[0]=1; } AnalogReading2 = analogRead(Inventor.Pot2); if(AnalogReading2 >=4095) { PotResults[1]=1; } AnalogReading3 = analogRead(Inventor.Pot3); if(AnalogReading3 >=4095) { PotResults[2]=1; } DisplayPotData2User(AnalogReading1, AnalogReading2, AnalogReading3); } void PotTestsToZero() { int AnalogReading1, AnalogReading2,AnalogReading3; AnalogReading1=0; AnalogReading2=0; AnalogReading3=0; AnalogReading1 = analogRead(Inventor.Pot1); if(AnalogReading1 == 0) { PotResults[0]=1; } AnalogReading2 = analogRead(Inventor.Pot2); if(AnalogReading2 == 0) { PotResults[1]=1; } AnalogReading3 = analogRead(Inventor.Pot3); if(AnalogReading3 == 0) { PotResults[2]=1; } DisplayPotData2User(AnalogReading1, AnalogReading2, AnalogReading3); } /*************************************************************************** *--------------------------SwitchTests Function--------------------------- * Used to determine if all the push buttons are working correctly. * When any of the buttons are pressed, it stores which button was pressed. * * USAGE * SwitchTests();// Scan all buttons for someone pressing them. * ***************************************************************************/ void SwitchTests() { if(digitalRead(Inventor.SW1) == HIGH) { digitalWrite(Inventor.LED1,LOW); } else if (digitalRead(Inventor.SW1) == LOW) { digitalWrite(Inventor.LED1,HIGH); SwitchResults[0]=1; } if(digitalRead(Inventor.SW2) == HIGH) { digitalWrite(Inventor.LED2,LOW); } else if (digitalRead(Inventor.SW2) == LOW) { digitalWrite(Inventor.LED2,HIGH); SwitchResults[1]=1; } if(digitalRead(Inventor.SW3) == HIGH) { digitalWrite(Inventor.LED3,LOW); } else if (digitalRead(Inventor.SW3) == LOW) { digitalWrite(Inventor.LED3,HIGH); SwitchResults[2]=1; delay(250);// Just allow the user to see the last LED lit up, or they wouldnt see it as it happens too fast. } } /*************************************************************************** *--------------------------ResetVariables Function--------------------------- * This is specific to the Inventor code,and do not reccomend you use this at all. * * USAGE * To call it, simply do this * * ResetVariables(); * ***************************************************************************/ void ResetVariables() { Serial.println(F("-----OTHER POTENTIAL CAUSES-----")); Serial.println(F("ESP32 not seated in J1 & J2 correctly. ")); Serial.println(F("Skipping test, standby...")); delay(9000);// If you want the delay to be shorter between failed message posts, lower this number. InventorTestsPassed = false; TestNumber++; MessagePrinted = false; UserTyped= ""; } /*************************************************************************** *--------------------------Troubleshoot Function--------------------------- * Used to tell the user what could be wrong * with thier Dr.Duino Inventor Shield if, a test fails. * It has one argument which must be passed in * * USAGE * To call it, simply do this * * TroubleShoot(true); This will put a short delay before telling the user * what could be wrong with thier device. * * OR * TroubleShoot(false); This will NOT put a short delay before telling the user * what could be wrong with thier device. * ***************************************************************************/ void TroubleShoot(int WhichTestFailed) { ClearSerialMonitorScreen(false); switch (WhichTestFailed) { case 1: Serial.println(F("-----------------Red LED Tests Failed----------------------")); Serial.println(F("1- Make sure jumpers JP1, JP2 & JP3 are in the M-O position.")); ResetVariables(); break; case 2: Serial.println(F("-----------------Switch Tests Failed----------------------")); Serial.println(F("1- Make sure jumpers JP5, JP6 & JP7 are in the M-O position.")); ResetVariables(); break; case 3: Serial.println(F("-----------------Potentiometer Test 1 Failed----------------------")); Serial.println(F("1- Make sure jumpers JP14, JP15 and JP16 are in the in M-O position.")); Serial.println(F("2-Potentiometers never reached an input voltage of 0V.")); ResetVariables(); break; case 4: Serial.println(F("-----------------Potentiometer Test 2 Failed----------------------")); Serial.println(F("1- Make sure jumpers JP14, JP15 and JP16 are in the in M-O position.")); Serial.println(F("2- Potentiometers never reached an input voltage of 3.3V")); ResetVariables(); break; case 5: Serial.println(F("-----------------LDR Test 1 FAILED----------------------")); Serial.println(F("No decrease in light value detected!")); Serial.println(F("1) If you are using the reroute it jumpers and breadboard, double check wiring first. ")); Serial.println(F("2) Make sure you are using the 10K ohm resistor. ")); Serial.println(F("3) Make sure jumper JP18 is installed in the O-M position. ")); Serial.println(F("4) Consider soldering the LDR into the board directly. Not required but will avoid wiring issues.")); Serial.println("-----------------OR---------------------------------------"); Serial.println(F("1) If you have soldered it into the board, make sure JP18 is in the M-O position.")); ResetVariables(); break; case 6: Serial.println(F("-----------------LDR Test 2 FAILED----------------------")); Serial.println(F("No increase in light value detected!")); Serial.println(F("1) If you are using the reroute it jumpers and breadboard, double check wiring first. ")); Serial.println(F("2) Make sure you are using the 10K ohm resistor. ")); Serial.println(F("3) Make sure jumper JP18 is installed in the O-M position. ")); Serial.println(F("4) Consider soldering the LDR into the board directly. Not required but will avoid wiring issues.")); Serial.println("-----------------OR---------------------------------------"); Serial.println(F("1) If you have soldered it into the board, make sure JP18 is in the M-O position.")); ResetVariables(); break; case 7: Serial.println(F("-----------------MP3 Player FAILED----------------------")); Serial.println(F("1) Make sure jumpers JP19 and JP20 are installed in the M-O position.")); Serial.println(F("2) Make sure the speaker is connected to the bottom of the board.")); Serial.println(F("3) Make sure the files are loaded onto the SD card correctly.")); Serial.println(F("4) Make sure an SD card is installed.")); Serial.println(F("Just a reminder, that the folder structure in the SD card matters.")); Serial.println(F("Refer to the manual for directions on loading the SD Card. Visit www.DrDuino.com/labs")); ResetVariables(); break; case 8: Serial.println(F("-----------------DHT11 Test FAILED----------------------")); Serial.println(F("No sensor detected!")); Serial.println(F("1) If you are using the reroute it jumpers and breadboard, double check wiring first. ")); Serial.println(F("2) Make sure you are using the 10K ohm resistor. ")); Serial.println(F("3) Make sure jumper JP4 is installed in the O-M position. ")); Serial.println(F("4) Consider soldering the DHT into the board directly. Not required but will avoid wiring issues.")); Serial.println(F("Visit www.DrDuino.com/labs for more information.")); Serial.println("-----------------OR---------------------------------------"); Serial.println(F("1) If you have soldered it into the board, make sure JP4 is in the M-O position.")); ResetVariables(); break; case 9: Serial.println(F("-----------------Relay Test FAILED----------------------")); Serial.println(F("Relay not installed!")); Serial.println(F("1) If you are using the reroute it jumpers and breadboard, double check wiring first. ")); Serial.println(F("2) Make sure jumper JP21 is installed in the O-M position. ")); Serial.println(F("3) Consider soldering the Relay into the board directly. Not required but will avoid wiring issues.")); Serial.println(F("See online manual for detailed instructions as to how to do this. Visit www.DrDuino.com/labs")); Serial.println("-----------------OR---------------------------------------"); Serial.println(F("1) If you have soldered it into the board, make sure JP21 is in the M-O position.")); ResetVariables(); break; case 10: Serial.println(F("-----------------Stepper Motor FAILED----------------------")); Serial.println(F("1) Verify Jumpers JP10, JP11, JP12, and JP13 are installed in the M-O position.")); Serial.println(F("2) Verify orientation of connector to board. It can only be installed one way. Refer to online manual www.DrDuino.com/labs")); ResetVariables(); break; case 11: Serial.println(F("-----------------Addressable LEDs FAILED----------------------")); Serial.println(F("1) Is J10 is installed?")); Serial.println(F("2) Make sure jumper JP9 is installed and in the M-O position.")); ResetVariables(); break; default: Serial.println(F("UKNOWN ISSUE")); Serial.println(F("Go to www.DrDuino.com and click on the help button in the bottom right hand corner.")); ResetVariables(); break; } }