Skip to content

Commit 2ac9032

Browse files
committed
add Charge_Check
1 parent 2381e56 commit 2ac9032

File tree

4 files changed

+141
-2
lines changed

4 files changed

+141
-2
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=PLEN5Stack
2-
version=1.0.5
2+
version=1.0.6
33
author=PLEN Project
44
maintainer=miya <[email protected]>
55
sentence=PLEN5Stack Library

src/PLEN5Stack.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ void PLEN5Stack::servoInitialSet()
7070
}
7171
}
7272

73+
void PLEN5Stack::motionSpeed(uint16_t num){
74+
if(0 <= num && num <= 20){
75+
motionSpeed = num;
76+
}
77+
}
78+
7379
void PLEN5Stack::setAngle(int16_t angle[], uint16_t msec)
7480
{
7581
float steps[SERVO_NUM_USED] = {};
76-
uint16_t motionSpeed = 10;//6; //"C++ speed" is so speedy.
82+
//uint16_t motionSpeed = 10;//6; //"C++ speed" is so speedy.
7783
msec = msec / motionSpeed;//default 10; Speed Adj
7884
for (uint8_t val = 0; val < SERVO_NUM_USED; val++)
7985
{

src/PLEN5Stack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class PLEN5Stack
5050
float servoAngle[SERVO_NUM_USED] = {1000, 630, 300, 600, 240, 600, 1000, 720};
5151
//int SERVO_SET_INIT[8] = {1000, 900, 300, 900, 800, 900, 1500, 900};
5252
bool initController = false;
53+
uint16_t motionSpeed = 10;
5354
//byte error;
5455
void write8(uint8_t addr, uint8_t cmd);
5556
void weep(uint16_t eepAdr, uint8_t num);

0 commit comments

Comments
 (0)