-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathArduinoGuitarHero.cpp
More file actions
63 lines (49 loc) · 1.56 KB
/
ArduinoGuitarHero.cpp
File metadata and controls
63 lines (49 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* ArduinoGuitarHero - Wii Guitar Hero Controller Library for Arduino
*
* Based off the wonderful ArduinoNunchuck Library by Gabriel Bianconi, http://www.gabrielbianconi.com/
* Under Copyright (c) 2014, Gabriel Bianconi All rights reserved.
*/
#include <Arduino.h>
#include <Wire.h>
#include "ArduinoGuitarHero.h"
#define ADDRESS 0x52
void ArduinoGuitarHero::init()
{
Wire.begin();
ArduinoGuitarHero::_sendByte(0x55, 0xF0);
ArduinoGuitarHero::_sendByte(0x00, 0xFB);
ArduinoGuitarHero::update();
}
void ArduinoGuitarHero::update()
{
int count = 0;
int values[6];
Wire.requestFrom(ADDRESS, 6);
while(Wire.available())
{
values[count] = Wire.read();
count++;
}
ArduinoGuitarHero::sX = values[0] - 192;
ArduinoGuitarHero::sY = values[1] - 192;
ArduinoGuitarHero::TB = values[2];
ArduinoGuitarHero::WB = values[3] - 239;
ArduinoGuitarHero::STRUM = (values[4] & 64) == 0 ? -1 : (values[5] & 1) == 0 ? 1 : 0;
ArduinoGuitarHero::BPlus = (values[4] & 4) == 0 ? 1 : 0;
ArduinoGuitarHero::BMinus = (values[4] & 16) == 0 ? 1 : 0;
ArduinoGuitarHero::BG = (values[5] & 16) == 0 ? 1 : 0;
ArduinoGuitarHero::BR = (values[5] & 64) == 0 ? 1 : 0;
ArduinoGuitarHero::BY = (values[5] & 8) == 0 ? 1 : 0;
ArduinoGuitarHero::BB = (values[5] & 32) == 0 ? 1 : 0;
ArduinoGuitarHero::BO = (values[5] & 128) == 0 ? 1 : 0;
ArduinoGuitarHero::_sendByte(0x00, 0x00);
}
void ArduinoGuitarHero::_sendByte(byte data, byte location)
{
Wire.beginTransmission(ADDRESS);
Wire.write(location);
Wire.write(data);
Wire.endTransmission();
delay(10);
}