|
| 1 | +/* |
| 2 | + PLEN5Stack Charge_Check.ino |
| 3 | + Copyright (c) 2019, |
| 4 | + - hkr352 @miya - https://github.com/hkr352 |
| 5 | + - PLEN Project Company Inc. - https://plen.jp |
| 6 | + This software is released under the MIT License. |
| 7 | + (See also : http://opensource.org/licenses/mit-license.php) |
| 8 | +*/ |
| 9 | +#include <M5Stack.h> |
| 10 | +#include <PLEN5Stack.h> |
| 11 | +#include <Adafruit_NeoPixel.h> //ver 1.3.4 |
| 12 | + |
| 13 | +#define IP5306_ADDR 117 |
| 14 | +#define IP5306_REG_SYS_CTL0 0x00 |
| 15 | +#define IP5306_REG_READ0 0x70 |
| 16 | +#define IP5306_REG_READ1 0x71 |
| 17 | +#define CHARGE_FULL_BIT 3 |
| 18 | + |
| 19 | +#define SCL 22 |
| 20 | +#define SDA 21 |
| 21 | +#define POWERSWITCH 5 |
| 22 | +#define LEDEYE 26 |
| 23 | +#define LED_COUNT 2 |
| 24 | +PLEN5Stack plen5stack; |
| 25 | +Adafruit_NeoPixel strip(LED_COUNT, LEDEYE, NEO_GRB + NEO_KHZ800); |
| 26 | +unsigned long time1; |
| 27 | + |
| 28 | +void setup() |
| 29 | +{ |
| 30 | + M5.begin(); |
| 31 | + |
| 32 | + pinMode(POWERSWITCH, OUTPUT); |
| 33 | + digitalWrite(POWERSWITCH, LOW); |
| 34 | + Wire.begin(SDA, SCL); |
| 35 | + plen5stack.begin(); //PLEN Servo init |
| 36 | + |
| 37 | + strip.begin(); |
| 38 | + strip.setBrightness(10); |
| 39 | + setColor(strip.Color( 0,255, 0),500); // Red |
| 40 | + //setColor(strip.Color( 0, 0,255),500); // Blue |
| 41 | + setColor(strip.Color(255,255, 0),500); // Yellow |
| 42 | + setColor(strip.Color(255, 0, 0),500); // Green |
| 43 | + |
| 44 | + digitalWrite(POWERSWITCH, HIGH); // motor power on |
| 45 | + plenMenu(); |
| 46 | + |
| 47 | + battery_level();delay(3000); |
| 48 | + |
| 49 | +} |
| 50 | + |
| 51 | +void loop() |
| 52 | +{ |
| 53 | + M5.update(); |
| 54 | + if(M5.BtnA.wasReleased()) |
| 55 | + { |
| 56 | + M5.Lcd.fillScreen(BLACK); |
| 57 | + M5.Lcd.setCursor(10, 10); |
| 58 | + M5.Lcd.setTextSize(6); |
| 59 | + M5.Lcd.println(" Hello !"); |
| 60 | + setColor(strip.Color(0,0,255),0); |
| 61 | + plen5stack.motion(0x29);//Patapata: Shake arms |
| 62 | + M5.Lcd.println("I'm PLEN"); |
| 63 | + M5.Lcd.println("5 Stack!"); |
| 64 | + plen5stack.motion(38);//Dance Twist |
| 65 | + M5.Lcd.fillScreen(BLACK); |
| 66 | + setColor(strip.Color(255,0,0),0); // Green |
| 67 | + plenMenu(); |
| 68 | + } |
| 69 | + else if(M5.BtnB.wasReleased()) |
| 70 | + { |
| 71 | + setColor(strip.Color(0,255,255),0); |
| 72 | + plen5stack.motion(0x46);//Walk |
| 73 | + plen5stack.motion(8);//Highfive |
| 74 | + setColor(strip.Color(255,0,0),0); |
| 75 | + } |
| 76 | + else if(M5.BtnC.wasReleased()) |
| 77 | + { |
| 78 | + plenBlink(strip.Color(255,0,0),100); |
| 79 | + }// if button |
| 80 | + |
| 81 | + if(millis()-time1 >= 1000){ |
| 82 | + time1 = millis(); |
| 83 | + battery_level(); |
| 84 | + }// 1 tick timer for debug |
| 85 | + |
| 86 | +} // loop |
| 87 | + |
| 88 | +void plenBlink(uint32_t color, int wait) |
| 89 | +{ |
| 90 | + setColor(strip.Color(0,0,0),wait); |
| 91 | + setColor(color,wait); |
| 92 | + setColor(strip.Color(0,0,0),wait); |
| 93 | + setColor(color,wait); |
| 94 | +} |
| 95 | + |
| 96 | +void plenMenu() |
| 97 | +{ |
| 98 | + M5.Lcd.fillScreen(BLACK); |
| 99 | + M5.Lcd.setCursor(5, 5); |
| 100 | + M5.Lcd.setTextColor(WHITE); |
| 101 | + M5.Lcd.setTextSize(1); |
| 102 | + M5.Lcd.println("PLEN5Stack"); |
| 103 | + |
| 104 | + M5.Lcd.setTextSize(6); |
| 105 | + M5.Lcd.println(""); |
| 106 | + M5.Lcd.println(""); |
| 107 | + M5.Lcd.println(""); |
| 108 | + M5.Lcd.println(" A B C "); |
| 109 | +} |
| 110 | + |
| 111 | +void setColor(uint32_t color, int wait) |
| 112 | +{ |
| 113 | + for(int i=0; i<strip.numPixels(); i++) |
| 114 | + { |
| 115 | + strip.setPixelColor(i, color); |
| 116 | + strip.show(); |
| 117 | + } |
| 118 | + delay(wait); |
| 119 | +} |
| 120 | + |
| 121 | +void battery_level() |
| 122 | +{ |
| 123 | + M5.Lcd.setTextSize(1); |
| 124 | + M5.Lcd.setCursor(5,15);//(0, 200); |
| 125 | + M5.Lcd.print("Battery Level: "); |
| 126 | + M5.Lcd.print(M5.Power.getBatteryLevel()); |
| 127 | + M5.Lcd.print("%"); |
| 128 | + M5.Lcd.setCursor(5,25);//(0, 220); |
| 129 | + if (M5.Power.getBatteryLevel() == -1){ |
| 130 | + M5.Lcd.print(" or Not USB IP5306"); |
| 131 | + } |
| 132 | +} |
0 commit comments