mirror of
https://github.com/digistump/DigistumpArduino.git
synced 2025-11-02 20:44:50 -08:00
switch to setup for Arduino Boards Manager
This commit is contained in:
65
digistump-avr/libraries/Nunchuk/ArduinoNunchuk.cpp
Normal file
65
digistump-avr/libraries/Nunchuk/ArduinoNunchuk.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* ArduinoNunchuk.cpp - Improved Wii Nunchuk library for Arduino
|
||||
*
|
||||
* Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
|
||||
*
|
||||
* Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
|
||||
*
|
||||
* Based on the following resources:
|
||||
* http://www.windmeadow.com/node/42
|
||||
* http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
|
||||
* http://wiibrew.org/wiki/Wiimote/Extension_Controllers
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <TinyWireM.h>
|
||||
#include "ArduinoNunchuk.h"
|
||||
|
||||
#define ADDRESS 0x52
|
||||
|
||||
void ArduinoNunchuk::init()
|
||||
{
|
||||
TinyWireM.begin();
|
||||
|
||||
ArduinoNunchuk::_sendByte(0x55, 0xF0);
|
||||
ArduinoNunchuk::_sendByte(0x00, 0xFB);
|
||||
|
||||
ArduinoNunchuk::update();
|
||||
}
|
||||
|
||||
void ArduinoNunchuk::update()
|
||||
{
|
||||
int count = 0;
|
||||
int values[6];
|
||||
|
||||
TinyWireM.requestFrom(ADDRESS, 6);
|
||||
|
||||
while(TinyWireM.available())
|
||||
{
|
||||
values[count] = TinyWireM.receive();
|
||||
count++;
|
||||
}
|
||||
|
||||
ArduinoNunchuk::analogX = values[0];
|
||||
ArduinoNunchuk::analogY = values[1];
|
||||
ArduinoNunchuk::accelX = (values[2] << 2) | ((values[5] >> 2) & 3);
|
||||
ArduinoNunchuk::accelY = (values[3] << 2) | ((values[5] >> 4) & 3);
|
||||
ArduinoNunchuk::accelZ = (values[4] << 2) | ((values[5] >> 6) & 3);
|
||||
ArduinoNunchuk::zButton = !((values[5] >> 0) & 1);
|
||||
ArduinoNunchuk::cButton = !((values[5] >> 1) & 1);
|
||||
|
||||
ArduinoNunchuk::_sendByte(0x00, 0x00);
|
||||
}
|
||||
|
||||
void ArduinoNunchuk::_sendByte(byte data, byte location)
|
||||
{
|
||||
TinyWireM.beginTransmission(ADDRESS);
|
||||
|
||||
TinyWireM.send(location);
|
||||
TinyWireM.send(data);
|
||||
|
||||
TinyWireM.endTransmission();
|
||||
|
||||
delay(10);
|
||||
}
|
||||
38
digistump-avr/libraries/Nunchuk/ArduinoNunchuk.h
Normal file
38
digistump-avr/libraries/Nunchuk/ArduinoNunchuk.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* ArduinoNunchuk.h - Improved Wii Nunchuk library for Arduino
|
||||
*
|
||||
* Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
|
||||
*
|
||||
* Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
|
||||
*
|
||||
* Based on the following resources:
|
||||
* http://www.windmeadow.com/node/42
|
||||
* http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
|
||||
* http://wiibrew.org/wiki/Wiimote/Extension_Controllers
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ArduinoNunchuk_H
|
||||
#define ArduinoNunchuk_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class ArduinoNunchuk
|
||||
{
|
||||
public:
|
||||
int analogX;
|
||||
int analogY;
|
||||
int accelX;
|
||||
int accelY;
|
||||
int accelZ;
|
||||
int zButton;
|
||||
int cButton;
|
||||
|
||||
void init();
|
||||
void update();
|
||||
|
||||
private:
|
||||
void _sendByte(byte data, byte location);
|
||||
};
|
||||
|
||||
#endif
|
||||
3
digistump-avr/libraries/Nunchuk/LICENSE.txt
Normal file
3
digistump-avr/libraries/Nunchuk/LICENSE.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
LICENSE
|
||||
|
||||
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
|
||||
15
digistump-avr/libraries/Nunchuk/README.txt
Normal file
15
digistump-avr/libraries/Nunchuk/README.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
ArduinoNunchuk - Improved Wii Nunchuk library for Arduino
|
||||
|
||||
Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
|
||||
|
||||
Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
|
||||
|
||||
Based on the following resources:
|
||||
- http://www.windmeadow.com/node/42
|
||||
- http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
|
||||
- http://wiibrew.org/wiki/Wiimote/Extension_Controllers
|
||||
|
||||
|
||||
INSTALLATION:
|
||||
|
||||
Copy the 'ArduinoNunchuk' folder, located in the same folder as this 'README' file, to the Arduino libraries folder (Arduino/libraries).
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* ArduinoNunchukDemo.ino
|
||||
*
|
||||
* Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
|
||||
*
|
||||
* Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <ArduinoNunchuk.h>
|
||||
|
||||
#define BAUDRATE 19200
|
||||
|
||||
ArduinoNunchuk nunchuk = ArduinoNunchuk();
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(BAUDRATE);
|
||||
nunchuk.init();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
nunchuk.update();
|
||||
|
||||
Serial.print(nunchuk.analogX, DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(nunchuk.analogY, DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(nunchuk.accelX, DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(nunchuk.accelY, DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(nunchuk.accelZ, DEC);
|
||||
Serial.print(' ');
|
||||
Serial.print(nunchuk.zButton, DEC);
|
||||
Serial.print(' ');
|
||||
Serial.println(nunchuk.cButton, DEC);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//DigiJoystick Nunchuck Demo
|
||||
|
||||
#include <DigiJoystick.h>
|
||||
#include <ArduinoNunchuk.h>
|
||||
#include <TinyWireM.h>
|
||||
|
||||
ArduinoNunchuk nunchuk = ArduinoNunchuk();
|
||||
|
||||
void setup() {
|
||||
nunchuk.init();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
nunchuk.update();
|
||||
DigiJoystick.setX((byte) nunchuk.analogX); // scroll X left to right repeatedly
|
||||
DigiJoystick.setY((byte) nunchuk.analogY);
|
||||
DigiJoystick.setXROT((byte) map(nunchuk.accelX,255,700,0,255));
|
||||
DigiJoystick.setYROT((byte) map(nunchuk.accelY,255,850,0,255));
|
||||
DigiJoystick.setZROT((byte) map(nunchuk.accelZ,255,750,0,255));
|
||||
int buttonByte = 0;
|
||||
bitWrite(buttonByte, 0, nunchuk.zButton);
|
||||
bitWrite(buttonByte, 1, nunchuk.cButton);
|
||||
DigiJoystick.setButtons((byte) buttonByte, (byte) 0);
|
||||
DigiJoystick.delay(10);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Digispark Nunchuck shield demo
|
||||
*
|
||||
* Uses arduinonunchuk - Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/ - http://www.gabrielbianconi.com/projects/arduinonunchuk/
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <ArduinoNunchuk.h>
|
||||
#include <DigiUSB.h>
|
||||
#include <TinyWireM.h>
|
||||
|
||||
ArduinoNunchuk nunchuk = ArduinoNunchuk();
|
||||
|
||||
void setup()
|
||||
{
|
||||
DigiUSB.begin();
|
||||
nunchuk.init();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
nunchuk.update();
|
||||
|
||||
DigiUSB.println(nunchuk.analogX, DEC);
|
||||
|
||||
DigiUSB.println(nunchuk.analogY, DEC);
|
||||
|
||||
DigiUSB.println(nunchuk.accelX, DEC);
|
||||
|
||||
DigiUSB.println(nunchuk.accelY, DEC);
|
||||
|
||||
DigiUSB.println(nunchuk.accelZ, DEC);
|
||||
|
||||
DigiUSB.println(nunchuk.zButton, DEC);
|
||||
|
||||
DigiUSB.println(nunchuk.cButton, DEC);
|
||||
|
||||
DigiUSB.delay(250);
|
||||
}
|
||||
3
digistump-avr/libraries/Nunchuk/keywords.txt
Normal file
3
digistump-avr/libraries/Nunchuk/keywords.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
ArduinoNunchuk KEYWORD1
|
||||
init KEYWORD2
|
||||
update KEYWORD2
|
||||
Reference in New Issue
Block a user