-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
382 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
PLEN5Stack PLEN_IMU.ino | ||
Copyright (c) 2019, | ||
- hkr352 @miya - https://github.com/hkr352 | ||
- PLEN Project Company Inc. - https://plen.jp | ||
This software is released under the MIT License. | ||
(See also : http://opensource.org/licenses/mit-license.php) | ||
*/ | ||
// define must ahead #include <M5Stack.h> | ||
#define M5STACK_MPU6886 | ||
// #define M5STACK_MPU9250 | ||
// #define M5STACK_MPU6050 | ||
// #define M5STACK_200Q | ||
|
||
#include <M5Stack.h> | ||
#include <PLEN5Stack.h> | ||
#include <Adafruit_NeoPixel.h> //ver 1.3.4 | ||
|
||
#define SCL 22 | ||
#define SDA 21 | ||
#define POWERSWITCH 5 | ||
#define LEDEYE 26 | ||
#define LED_COUNT 2 | ||
PLEN5Stack plen5stack; | ||
Adafruit_NeoPixel strip(LED_COUNT, LEDEYE, NEO_GRB + NEO_KHZ800); | ||
|
||
float accX = 0.0F; | ||
float accY = 0.0F; | ||
float accZ = 0.0F; | ||
bool motorEnable = true; | ||
bool viewReset = false; | ||
unsigned long time1; | ||
|
||
void setup() | ||
{ | ||
M5.begin(); | ||
M5.Power.begin(); | ||
M5.IMU.Init(); | ||
|
||
pinMode(POWERSWITCH, OUTPUT); | ||
digitalWrite(POWERSWITCH, LOW); | ||
Wire.begin(SDA, SCL); | ||
plen5stack.servoInitialSet(); //PLEN Servo init | ||
|
||
strip.begin(); | ||
strip.setBrightness(10); | ||
setColor(strip.Color(255, 0, 0),500); // Green | ||
|
||
digitalWrite(POWERSWITCH, HIGH); // motor power on | ||
|
||
} | ||
|
||
void loop() | ||
{ | ||
M5.update(); | ||
M5.IMU.getAccelData(&accX,&accY,&accZ); | ||
M5.Lcd.setCursor(0, 110); | ||
M5.Lcd.setTextColor(GREEN , BLACK); | ||
M5.Lcd.setTextSize(2); | ||
M5.Lcd.printf(" %5.2f %5.2f %5.2f ", accX, accY, accZ); | ||
M5.Lcd.setCursor(220, 132); | ||
M5.Lcd.print(" G"); | ||
|
||
if(accY < 0.3) | ||
{ | ||
M5.Lcd.setCursor(10, 50); | ||
M5.Lcd.setTextColor(RED); | ||
M5.Lcd.setTextSize(6); | ||
M5.Lcd.println("HELP ME!"); | ||
setColor(strip.Color( 0,255, 0),500); | ||
if (motorEnable) | ||
{ | ||
plen5stack.motion(0x29); | ||
delay(1000); | ||
} | ||
viewReset = true; | ||
}else | ||
{ | ||
if (viewReset) | ||
{ | ||
M5.Lcd.fillScreen(BLACK); | ||
setColor(strip.Color(255, 0, 0),500); | ||
viewReset = false; | ||
} | ||
} | ||
|
||
if(M5.BtnC.wasReleased()) | ||
{ | ||
motorEnable = !motorEnable; | ||
} | ||
//delay(1); | ||
} // loop | ||
|
||
void plenBlink(uint32_t color, int wait) | ||
{ | ||
setColor(strip.Color(0,0,0),wait); | ||
setColor(color,wait); | ||
setColor(strip.Color(0,0,0),wait); | ||
setColor(color,wait); | ||
} | ||
|
||
void setColor(uint32_t color, int wait) | ||
{ | ||
for(int i=0; i<strip.numPixels(); i++) | ||
{ | ||
strip.setPixelColor(i, color); | ||
strip.show(); | ||
} | ||
delay(wait); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
PLEN5Stack PlayMotion.ino | ||
Copyright (c) 2019, | ||
- hkr352 @miya - https://github.com/hkr352 | ||
- PLEN Project Company Inc. - https://plen.jp | ||
This software is released under the MIT License. | ||
(See also : http://opensource.org/licenses/mit-license.php) | ||
*/ | ||
#include <M5Stack.h> | ||
#include <PLEN5Stack.h> | ||
#include <Adafruit_NeoPixel.h> //ver 1.3.4 | ||
|
||
#define SCL 22 | ||
#define SDA 21 | ||
#define POWERSWITCH 5 | ||
#define LEDEYE 26 | ||
#define LED_COUNT 2 | ||
PLEN5Stack plen5stack; | ||
Adafruit_NeoPixel strip(LED_COUNT, LEDEYE, NEO_GRB + NEO_KHZ800); | ||
//unsigned long time1; | ||
|
||
int16_t angle[8]= {0}; | ||
|
||
void setup() | ||
{ | ||
M5.begin(); | ||
|
||
pinMode(POWERSWITCH, OUTPUT); | ||
digitalWrite(POWERSWITCH, LOW); | ||
Wire.begin(SDA, SCL); | ||
plen5stack.servoInitialSet(); //PLEN Servo init | ||
|
||
strip.begin(); | ||
strip.setBrightness(10); | ||
setColor(strip.Color(255, 0, 0),500); // Green | ||
digitalWrite(POWERSWITCH, HIGH); // motor power on | ||
plenMenu(); | ||
} | ||
|
||
void loop() | ||
{ | ||
M5.update(); | ||
if(M5.BtnA.wasReleased()) | ||
{ | ||
//Standard motion | ||
plen5stack.motion(0x46);// Walk Forward | ||
// plen5stack.motion(0x47);// Walk Left Turn | ||
// plen5stack.motion(0x48);// Walk Right Turn | ||
// plen5stack.motion(0x49);// Walk Back | ||
// plen5stack.motion(0x00);// Left step | ||
// plen5stack.motion(0x01);// Forward step | ||
// plen5stack.motion(0x02);// Right step | ||
// plen5stack.motion(0x03);// A hem | ||
// plen5stack.motion(0x04);// Bow | ||
// plen5stack.motion(0x05);// Propose | ||
// plen5stack.motion(0x06);// Hug | ||
// plen5stack.motion(0x07);// Clap | ||
// plen5stack.motion(0x08);// Highfive | ||
// plen5stack.motion(0x29);// Shake Arms | ||
} | ||
else if(M5.BtnB.wasReleased()) | ||
{ | ||
// Soccer motion | ||
// plen5stack.motion(0x14);// Defense Left Step | ||
// plen5stack.motion(0x15);// Dribble | ||
// plen5stack.motion(0x16);// Defense Right Step | ||
// plen5stack.motion(0x17);// Left Kick | ||
// plen5stack.motion(0x18);// Long Dribble | ||
plen5stack.motion(0x19);// Right Kick | ||
// plen5stack.motion(0x1a);// Pass To Left | ||
// plen5stack.motion(0x1b);// Pass It To Me | ||
// plen5stack.motion(0x1c);// Pass To Right | ||
} | ||
else if(M5.BtnC.wasReleased()) | ||
{ | ||
// Dance motion | ||
// plen5stack.motion(0x1c);// Dance Left Step | ||
// plen5stack.motion(0x1c);// Dance Forward Step | ||
// plen5stack.motion(0x1c);// Dance Right Step | ||
// plen5stack.motion(0x1c);// Dance Fisnish Pose | ||
// plen5stack.motion(0x1c);// Dance Up Down | ||
// plen5stack.motion(0x1c);// Wiggle Dance | ||
// plen5stack.motion(0x1c);// Dance Back Step | ||
// plen5stack.motion(0x1c);// Dance Bow | ||
plen5stack.motion(0x1c);// Twist Dance | ||
}// if button | ||
|
||
// Box motion | ||
// plen5stack.motion(0x0a); | ||
// plen5stack.motion(0x0b); | ||
// plen5stack.motion(0x0c); | ||
// plen5stack.motion(0x0d); | ||
// plen5stack.motion(0x0e); | ||
// plen5stack.motion(0x0f); | ||
// plen5stack.motion(0x10); | ||
// plen5stack.motion(0x11); | ||
// plen5stack.motion(0x12); | ||
|
||
} // loop | ||
|
||
void plenBlink(uint32_t color, int wait) | ||
{ | ||
setColor(strip.Color(0,0,0),wait); | ||
setColor(color,wait); | ||
setColor(strip.Color(0,0,0),wait); | ||
setColor(color,wait); | ||
} | ||
|
||
void plenMenu() | ||
{ | ||
M5.Lcd.fillScreen(BLACK); | ||
M5.Lcd.setCursor(5, 5); | ||
M5.Lcd.setTextColor(WHITE); | ||
M5.Lcd.setTextSize(1); | ||
M5.Lcd.println("PLEN5Stack"); | ||
|
||
M5.Lcd.setTextSize(6); | ||
M5.Lcd.println(""); | ||
M5.Lcd.println(""); | ||
M5.Lcd.println(""); | ||
M5.Lcd.println(" A B C "); | ||
} | ||
|
||
void setColor(uint32_t color, int wait) | ||
{ | ||
for(int i=0; i<strip.numPixels(); i++) | ||
{ | ||
strip.setPixelColor(i, color); | ||
strip.show(); | ||
} | ||
delay(wait); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
PLEN5Stack Servo.ino | ||
Copyright (c) 2019, | ||
- hkr352 @miya - https://github.com/hkr352 | ||
- PLEN Project Company Inc. - https://plen.jp | ||
This software is released under the MIT License. | ||
(See also : http://opensource.org/licenses/mit-license.php) | ||
*/ | ||
#include <M5Stack.h> | ||
#include <PLEN5Stack.h> | ||
#include <Adafruit_NeoPixel.h> //ver 1.3.4 | ||
|
||
#define SCL 22 | ||
#define SDA 21 | ||
#define POWERSWITCH 5 | ||
#define LEDEYE 26 | ||
#define LED_COUNT 2 | ||
PLEN5Stack plen5stack; | ||
Adafruit_NeoPixel strip(LED_COUNT, LEDEYE, NEO_GRB + NEO_KHZ800); | ||
//unsigned long time1; | ||
|
||
int16_t angle[8]= {0}; | ||
|
||
void setup() | ||
{ | ||
M5.begin(); | ||
|
||
pinMode(POWERSWITCH, OUTPUT); | ||
digitalWrite(POWERSWITCH, LOW); | ||
Wire.begin(SDA, SCL); | ||
plen5stack.servoInitialSet(); //PLEN Servo init | ||
|
||
strip.begin(); | ||
strip.setBrightness(10); | ||
setColor(strip.Color(255, 0, 0),500); // Green | ||
|
||
digitalWrite(POWERSWITCH, HIGH); // motor power on | ||
plenMenu(); | ||
} | ||
|
||
void loop() | ||
{ | ||
M5.update(); | ||
if(M5.BtnA.wasReleased()) | ||
{ | ||
// How to move the servo motor one by one. | ||
// plen5stack.servoWrite(servo number , degree); | ||
plen5stack.servoWrite(2,90); | ||
plen5stack.servoWrite(6,40); | ||
delay(500); | ||
plen5stack.servoWrite(2,30); | ||
plen5stack.servoWrite(6,100); | ||
delay(500); | ||
} | ||
else if(M5.BtnB.wasReleased()) | ||
{ | ||
// How to move multiple servo motors simultaneously. | ||
for(int i=0; i<2; i++) | ||
{ | ||
// angle [ servo number ] = angle; | ||
// plen5stack.setAngle(angle, msec); | ||
|
||
// Initial angle of Servo motor | ||
// 0:1000, 1:630, 2:300, 3:600 | ||
// 4:240, 5:600, 6:1000, 7:720 | ||
angle[1] = 900; | ||
angle[2] = -900; | ||
angle[5] = -900; | ||
angle[6] = 900; | ||
plen5stack.setAngle(angle,500); | ||
angle[1] = 0; | ||
angle[2] = 0; | ||
angle[5] = 0; | ||
angle[6] = 0; | ||
plen5stack.setAngle(angle,500); | ||
} | ||
} | ||
else if(M5.BtnC.wasReleased()) | ||
{ | ||
for(int i=0; i<2; i++) | ||
{ | ||
angle[4] = -1393; | ||
angle[0] = 0; | ||
plen5stack.setAngle(angle,500); | ||
angle[4] = -413; | ||
angle[0] = 1121; | ||
plen5stack.setAngle(angle,500); | ||
} | ||
angle[0] = 0; | ||
angle[4] = 0; | ||
plen5stack.setAngle(angle,500); | ||
}// if button | ||
|
||
//if(millis()-time1 >= 1000){ | ||
// time1 = millis(); | ||
//}// 1 tick timer for debug | ||
|
||
} // loop | ||
|
||
void angleReset() | ||
{ | ||
for(int i=0; i<8; i++) | ||
{ | ||
angle[i] = 0; | ||
} | ||
} | ||
|
||
void plenBlink(uint32_t color, int wait) | ||
{ | ||
setColor(strip.Color(0,0,0),wait); | ||
setColor(color,wait); | ||
setColor(strip.Color(0,0,0),wait); | ||
setColor(color,wait); | ||
} | ||
|
||
void plenMenu() | ||
{ | ||
M5.Lcd.fillScreen(BLACK); | ||
M5.Lcd.setCursor(5, 5); | ||
M5.Lcd.setTextColor(WHITE); | ||
M5.Lcd.setTextSize(1); | ||
M5.Lcd.println("PLEN5Stack"); | ||
|
||
M5.Lcd.setTextSize(6); | ||
M5.Lcd.println(""); | ||
M5.Lcd.println(""); | ||
M5.Lcd.println(""); | ||
M5.Lcd.println(" A B C "); | ||
} | ||
|
||
void setColor(uint32_t color, int wait) | ||
{ | ||
for(int i=0; i<strip.numPixels(); i++) | ||
{ | ||
strip.setPixelColor(i, color); | ||
strip.show(); | ||
} | ||
delay(wait); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters