source: rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/cores/validation/validation_chuck/test.cpp@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 1.6 KB
Line 
1#include <Arduino.h>
2#include <Wire.h>
3
4uint8_t accx,accy,zbut,cbut ;
5
6void setup()
7{
8 Serial5.begin( 115200 ) ;
9 Serial5.println("nunchuk init");
10
11 Wire.begin(); // join i2c bus as master
12 Wire.beginTransmission(0x52);// transmit to device 0x52
13 Wire.write((uint8_t)0xF0);// sends sent a zero.
14 Wire.write((uint8_t)0x55);// sends sent a zero.
15 Wire.write((uint8_t)0xFB);// sends sent a zero.
16 Wire.write((uint8_t)0x00);// sends sent a zero.
17 Wire.endTransmission();// stop transmitting
18
19 Serial5.println( "WiiChukDemo ready" ) ;
20 delay(100);
21}
22
23void loop()
24{
25 Wire.requestFrom(0x52, 6);
26
27 uint8_t jX = Wire.read();
28 uint8_t jY = Wire.read();
29 uint8_t accX = Wire.read();
30 uint8_t accY = Wire.read();
31 uint8_t accZ = Wire.read();
32 uint8_t misc = Wire.read();
33
34 Serial5.print("Joy : ");
35 Serial5.print(jX);
36 Serial5.print(", ");
37 Serial5.print(jY);
38
39 Serial5.print("\tAcc : ");
40 Serial5.print(accX);
41 Serial5.print(", ");
42 Serial5.print(accY);
43 Serial5.print(", ");
44 Serial5.print(accZ);
45
46 Serial5.print("\tBtn : ");
47 Serial5.print(" [");
48 Serial5.print(misc);
49 Serial5.print("] ");
50
51 switch(misc & 0x3ul)
52 {
53 case 0x0ul:
54 Serial5.println("Z");
55 break;
56
57 case 0x1ul:
58 Serial5.println("C");
59 break;
60
61 case 0x2ul:
62 Serial5.println("C + Z");
63 break;
64
65 case 0x3ul:
66 Serial5.println("No key");
67 break;
68
69 default:
70 break;
71 }
72
73 Wire.beginTransmission(0x52);// transmit to device 0x52
74 Wire.write((uint8_t)0x00);// sends sent a zero.
75 Wire.endTransmission();// stop transmitting
76
77 delay(100);
78
79}
Note: See TracBrowser for help on using the repository browser.