Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: robocon2017mbed_control_R
Fork of MyLib by
Revision 3:e7a900958f54, committed 2017-05-11
- Comitter:
- gaku_sigu
- Date:
- Thu May 11 07:31:39 2017 +0000
- Parent:
- 2:7b7821addb45
- Child:
- 4:ae9dc8d5c37e
- Commit message:
- Add radian
Changed in this revision
| Nunchuck/Nunchuck.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Nunchuck/Nunchuck.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Nunchuck/Nunchuck.cpp Thu May 11 07:10:17 2017 +0000
+++ b/Nunchuck/Nunchuck.cpp Thu May 11 07:31:39 2017 +0000
@@ -13,7 +13,7 @@
bool Nunchuck::init()
{
unsigned char cmd[] = {0x40, 0x00};
- if (I2C::write(ADDR, (const char*)cmd, sizeof(cmd)) == 0)
+ if (I2C::write(NUNCHUCK_ADDR, (const char*)cmd, sizeof(cmd)) == 0)
return 1;
else
return 0;
@@ -49,8 +49,8 @@
getdata();
int8_t temp;
temp = data[0] - 128;
-#if ANALOGDATA
- if(-1*(DEADZONE) < temp && temp < DEADZONE)
+#if NUNCHUCK_ANALOGDATA
+ if(-1*(NUNCHUCK_DEADZONE) < temp && temp < NUNCHUCK_DEADZONE)
temp = 0;
#else
if(-50 < temp && temp < 50)
@@ -69,8 +69,8 @@
getdata();
int8_t temp;
temp = data[1] - 128;
-#if ANALOGDATA
- if(-1*(DEADZONE) < temp && temp < DEADZONE)
+#if NUNCHUCK_ANALOGDATA
+ if(-1*(NUNCHUCK_DEADZONE) < temp && temp < NUNCHUCK_DEADZONE)
temp = 0;
#else
if(-50 < temp && temp < 50)
@@ -84,6 +84,14 @@
}
+double Nunchuck::analograd()
+{
+ double x = analogx();
+ double y = analogy();
+
+ return atan2(y,x);
+}
+
int Nunchuck::accx()
{
getdata();
--- a/Nunchuck/Nunchuck.h Thu May 11 07:10:17 2017 +0000
+++ b/Nunchuck/Nunchuck.h Thu May 11 07:31:39 2017 +0000
@@ -4,9 +4,9 @@
#include "mbed.h"
-#define ANALOGDATA 1 //1 : analog 0 : degital
-#define DEADZONE 6 //analog stick's deadzone
-#define ADDR 0xA4 // 0x52 << 1
+#define NUNCHUCK_ANALOGDATA 1 //1 : analog 0 : degital
+#define NUNCHUCK_DEADZONE 6 //analog stick's deadzone
+#define NUNCHUCK_ADDR 0xA4 // 0x52 << 1
class Nunchuck : I2C
{
@@ -15,6 +15,7 @@
Nunchuck(PinName SDA, PinName SCL);
int8_t analogx();
int8_t analogy();
+ double analograd();
int accx();
int accy();
int accz ();
