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_contoroler_L2
Fork of MyLib by
Revision 12:479a1f294781, committed 2017-10-24
- Comitter:
- kikoaac
- Date:
- Tue Oct 24 13:59:46 2017 +0000
- Parent:
- 11:08d8bd103eda
- Commit message:
- ????
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 Fri Oct 13 09:35:30 2017 +0000
+++ b/Nunchuck/Nunchuck.cpp Tue Oct 24 13:59:46 2017 +0000
@@ -6,15 +6,19 @@
flag = 0;
for(int i = 0; i < 6; i++)
data[i] = 0;
+ timer.start();
init();
- timer.start();
+ wait(0.2);
+ offset_();
}
bool Nunchuck::init()
{
unsigned char cmd[] = {0x40, 0x00};
if (I2C::write(NUNCHUCK_ADDR, (const char*)cmd, sizeof(cmd)) == 0)
+ {
return 1;
+ }
else
return 0;
}
@@ -25,6 +29,7 @@
return;
+ //__disable_irq(); // 禁止
if(flag) {
const unsigned char cmd[] = {0x00};
if (I2C::write(NUNCHUCK_ADDR, (const char*)cmd, sizeof(cmd)) == 0)
@@ -41,14 +46,14 @@
}
else
flag = init();
-
+ //__enable_irq(); // 許可
timer.reset();
}
int8_t Nunchuck::analogx()
{
- getdata();
+ //getdata();
int8_t temp;
temp = data[0] - 128;
#if NUNCHUCK_ANALOGDATA
@@ -62,13 +67,13 @@
else if(temp >= 50)
temp = 1;
#endif
- return temp;
+ return offset == true ? temp - offsetX : temp;
}
int8_t Nunchuck::analogy()
{
- getdata();
+ //getdata();
int8_t temp;
temp = data[1] - 128;
#if NUNCHUCK_ANALOGDATA
@@ -82,7 +87,8 @@
else if(temp >= 50)
temp = 1;
#endif
- return temp;
+
+ return offset == true ? temp - offsetY : temp;
}
@@ -141,13 +147,13 @@
bool Nunchuck::buttonz()
{
- getdata();
+ //getdata();
return !(data[5] & 0x01);
}
bool Nunchuck::buttonc()
{
- getdata();
+ //getdata();
return !(data[5] & 0x02);
}
--- a/Nunchuck/Nunchuck.h Fri Oct 13 09:35:30 2017 +0000
+++ b/Nunchuck/Nunchuck.h Tue Oct 24 13:59:46 2017 +0000
@@ -26,12 +26,34 @@
bool buttonc();
bool buttonz();
bool init();
-
+ void getdata();
+ void offset_(){
+ offsetX = 0;
+ offsetY = 0;
+ offset = false;
+ wait(0.2);
+ //for(int i = 0;i<20;i++){
+ offsetX = 0;//(char)analogx();
+ offsetY = 7;//(char)analogy();
+ //2ごうき
+ //x:252
+ //y:9
+ //1ごうき
+ //x:0
+ //y:7
+ //}
+ //printf("\n%d , %d \n",offsetX,offsetY);
+ offset = true;
+ //offsetX= offsetX/20;
+ //offsetY= offsetY/20;
+ }
private:
Timer timer;
bool flag;
char data[6];
- void getdata();
+ int offsetX;
+ int offsetY;
+ bool offset;
};
#endif
\ No newline at end of file
