Skip to content

Commit 6e722be

Browse files
author
Erik Kettenburg
committed
fix motor shield example, add nunchuck and temp shield examples
1 parent cda5631 commit 6e722be

File tree

16 files changed

+1415
-4
lines changed

16 files changed

+1415
-4
lines changed

examples/Digispark_Examples/MotorShield/MotorShield.ino

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ int MotorBSpeed = 1;
1111
// the setup routine runs once when you press reset:
1212
void setup() {
1313
// initialize the outputs.
14-
pinMode(led, OUTPUT);
15-
pinMode(led, OUTPUT);
16-
pinMode(led, OUTPUT);
17-
pinMode(led, OUTPUT);
14+
pinMode(MotorADir, OUTPUT);
15+
pinMode(MotorASpeed, OUTPUT);
16+
pinMode(MotorBDir, OUTPUT);
17+
pinMode(MotorBSpeed, OUTPUT);
1818
}
1919

2020
// the loop routine runs over and over again forever:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* ArduinoNunchuk.cpp - Improved Wii Nunchuk library for Arduino
3+
*
4+
* Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
5+
*
6+
* Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
7+
*
8+
* Based on the following resources:
9+
* http://www.windmeadow.com/node/42
10+
* http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
11+
* http://wiibrew.org/wiki/Wiimote/Extension_Controllers
12+
*
13+
*/
14+
15+
#include <Arduino.h>
16+
#include <TinyWireM.h>
17+
#include "ArduinoNunchuk.h"
18+
19+
#define ADDRESS 0x52
20+
21+
void ArduinoNunchuk::init()
22+
{
23+
TinyWireM.begin();
24+
25+
ArduinoNunchuk::_sendByte(0x55, 0xF0);
26+
ArduinoNunchuk::_sendByte(0x00, 0xFB);
27+
28+
ArduinoNunchuk::update();
29+
}
30+
31+
void ArduinoNunchuk::update()
32+
{
33+
int count = 0;
34+
int values[6];
35+
36+
TinyWireM.requestFrom(ADDRESS, 6);
37+
38+
while(TinyWireM.available())
39+
{
40+
values[count] = TinyWireM.receive();
41+
count++;
42+
}
43+
44+
ArduinoNunchuk::analogX = values[0];
45+
ArduinoNunchuk::analogY = values[1];
46+
ArduinoNunchuk::accelX = (values[2] << 2) | ((values[5] >> 2) & 3);
47+
ArduinoNunchuk::accelY = (values[3] << 2) | ((values[5] >> 4) & 3);
48+
ArduinoNunchuk::accelZ = (values[4] << 2) | ((values[5] >> 6) & 3);
49+
ArduinoNunchuk::zButton = !((values[5] >> 0) & 1);
50+
ArduinoNunchuk::cButton = !((values[5] >> 1) & 1);
51+
52+
ArduinoNunchuk::_sendByte(0x00, 0x00);
53+
}
54+
55+
void ArduinoNunchuk::_sendByte(byte data, byte location)
56+
{
57+
TinyWireM.beginTransmission(ADDRESS);
58+
59+
TinyWireM.send(location);
60+
TinyWireM.send(data);
61+
62+
TinyWireM.endTransmission();
63+
64+
delay(10);
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* ArduinoNunchuk.h - Improved Wii Nunchuk library for Arduino
3+
*
4+
* Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
5+
*
6+
* Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
7+
*
8+
* Based on the following resources:
9+
* http://www.windmeadow.com/node/42
10+
* http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
11+
* http://wiibrew.org/wiki/Wiimote/Extension_Controllers
12+
*
13+
*/
14+
15+
#ifndef ArduinoNunchuk_H
16+
#define ArduinoNunchuk_H
17+
18+
#include <Arduino.h>
19+
20+
class ArduinoNunchuk
21+
{
22+
public:
23+
int analogX;
24+
int analogY;
25+
int accelX;
26+
int accelY;
27+
int accelZ;
28+
int zButton;
29+
int cButton;
30+
31+
void init();
32+
void update();
33+
34+
private:
35+
void _sendByte(byte data, byte location);
36+
};
37+
38+
#endif
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
LICENSE
2+
3+
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.

libraries/DigisparkNunchuk/README.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ArduinoNunchuk - Improved Wii Nunchuk library for Arduino
2+
3+
Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
4+
5+
Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
6+
7+
Based on the following resources:
8+
- http://www.windmeadow.com/node/42
9+
- http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/
10+
- http://wiibrew.org/wiki/Wiimote/Extension_Controllers
11+
12+
13+
INSTALLATION:
14+
15+
Copy the 'ArduinoNunchuk' folder, located in the same folder as this 'README' file, to the Arduino libraries folder (Arduino/libraries).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* ArduinoNunchukDemo.ino
3+
*
4+
* Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/
5+
*
6+
* Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/
7+
*
8+
*/
9+
10+
#include <Wire.h>
11+
#include <ArduinoNunchuk.h>
12+
13+
#define BAUDRATE 19200
14+
15+
ArduinoNunchuk nunchuk = ArduinoNunchuk();
16+
17+
void setup()
18+
{
19+
Serial.begin(BAUDRATE);
20+
nunchuk.init();
21+
}
22+
23+
void loop()
24+
{
25+
nunchuk.update();
26+
27+
Serial.print(nunchuk.analogX, DEC);
28+
Serial.print(' ');
29+
Serial.print(nunchuk.analogY, DEC);
30+
Serial.print(' ');
31+
Serial.print(nunchuk.accelX, DEC);
32+
Serial.print(' ');
33+
Serial.print(nunchuk.accelY, DEC);
34+
Serial.print(' ');
35+
Serial.print(nunchuk.accelZ, DEC);
36+
Serial.print(' ');
37+
Serial.print(nunchuk.zButton, DEC);
38+
Serial.print(' ');
39+
Serial.println(nunchuk.cButton, DEC);
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//DigiJoystick Nunchuck Demo
2+
3+
#include <DigiJoystick.h>
4+
#include <ArduinoNunchuk.h>
5+
#include <TinyWireM.h>
6+
7+
ArduinoNunchuk nunchuk = ArduinoNunchuk();
8+
9+
void setup() {
10+
nunchuk.init();
11+
}
12+
13+
14+
void loop() {
15+
nunchuk.update();
16+
DigiJoystick.setX((byte) nunchuk.analogX); // scroll X left to right repeatedly
17+
DigiJoystick.setY((byte) nunchuk.analogY);
18+
DigiJoystick.setXROT((byte) map(nunchuk.accelX,255,700,0,255));
19+
DigiJoystick.setYROT((byte) map(nunchuk.accelY,255,850,0,255));
20+
DigiJoystick.setZROT((byte) map(nunchuk.accelZ,255,750,0,255));
21+
int buttonByte = 0;
22+
bitWrite(buttonByte, 0, nunchuk.zButton);
23+
bitWrite(buttonByte, 1, nunchuk.cButton);
24+
DigiJoystick.setButtons((byte) buttonByte, (byte) 0);
25+
DigiJoystick.delay(10);
26+
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Digispark Nunchuck shield demo
3+
*
4+
* Uses arduinonunchuk - Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/ - http://www.gabrielbianconi.com/projects/arduinonunchuk/
5+
*
6+
*/
7+
8+
9+
#include <ArduinoNunchuk.h>
10+
#include <DigiUSB.h>
11+
#include <TinyWireM.h>
12+
13+
ArduinoNunchuk nunchuk = ArduinoNunchuk();
14+
15+
void setup()
16+
{
17+
DigiUSB.begin();
18+
nunchuk.init();
19+
}
20+
21+
void loop()
22+
{
23+
nunchuk.update();
24+
25+
DigiUSB.println(nunchuk.analogX, DEC);
26+
27+
DigiUSB.println(nunchuk.analogY, DEC);
28+
29+
DigiUSB.println(nunchuk.accelX, DEC);
30+
31+
DigiUSB.println(nunchuk.accelY, DEC);
32+
33+
DigiUSB.println(nunchuk.accelZ, DEC);
34+
35+
DigiUSB.println(nunchuk.zButton, DEC);
36+
37+
DigiUSB.println(nunchuk.cButton, DEC);
38+
39+
DigiUSB.delay(250);
40+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ArduinoNunchuk KEYWORD1
2+
init KEYWORD2
3+
update KEYWORD2

0 commit comments

Comments
 (0)