Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. // MyProjectThing.ino
  2. // COM3505 2018 project template sketch. Do your project code here.
  3. // Out of the box the sketch is configured to kick the tyres on all the
  4. // modules, and allow stepping through tests via the touch screen. Change the
  5. // TestScreen::activate(true); to false to change this behaviour.
  6.  
  7. #include "unphone.h"
  8.  
  9. void setup() {
  10. Wire.setClock(100000); // higher rates trigger an IOExpander bug
  11. UNPHONE_DBG = true;
  12. Serial.begin(115200); // init the serial line
  13.  
  14. // fire up IĀ²C, and the unPhone's IOExpander library
  15. Wire.begin();
  16. IOExpander::begin();
  17.  
  18. checkPowerSwitch(); // check if power switch is now off & if so shutdown
  19.  
  20. // which board version are we running?
  21. int version = IOExpander::getVersionNumber(), spin;
  22. if(version == 7) spin = 4;
  23. Serial.printf("starting, running on spin %d\n", spin);
  24.  
  25. // show initial test screen on the LCD
  26. IOExpander::digitalWrite(IOExpander::BACKLIGHT, LOW);
  27. tft.begin(HX8357D);
  28. TestScreen::activate(true);
  29. TestScreen::init();
  30. IOExpander::digitalWrite(IOExpander::BACKLIGHT, HIGH);
  31.  
  32. if(! ts.begin()) { // init the touchscreen
  33. D("failed to start touchscreen controller");
  34. TestScreen::fail("TOUCH");
  35. delay(3000);
  36. } else {
  37. D("touchscreen started");
  38. }
  39.  
  40. if(!accel.begin()) // set up the accelerometer
  41. {
  42. D("Failed to start accelerometer");
  43. TestScreen::fail("ACCEL");
  44. delay(3000);
  45. }
  46.  
  47. i2s_config(); // configure the I2S bus
  48.  
  49. pinMode(IR_LEDS, OUTPUT); // IR_LED pin
  50.  
  51. // set up the SD card
  52. IOExpander::digitalWrite(IOExpander::SD_CS, LOW);
  53. if(!SD.begin(-1)) {
  54. D("Card Mount Failed");
  55. TestScreen::fail("SD CARD");
  56. delay(3000);
  57. }
  58. IOExpander::digitalWrite(IOExpander::SD_CS, HIGH);
  59.  
  60. if(! musicPlayer.begin()) { // initialise the music player
  61. D("Couldn't find VS1053, do you have the right pins defined?");
  62. TestScreen::fail("AUDIO");
  63. delay(3000);
  64. } else {
  65. D("VS1053 found");
  66. }
  67.  
  68. // send a LoRaWAN message to TTN
  69. lmic_init();
  70. lmic_do_send(&sendjob);
  71. }
  72.  
  73. void loop() {
  74. bool usbPowerOn = checkPowerSwitch(); // shutdown if switch off
  75.  
  76. TestScreen::testSequence(usbPowerOn); // run a test on all modules
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement