Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- const uint8_t I2C_ADDRESS = 0x52; //The original Nunchuk's I2C address
- int poti = 0; //Potentiometer for testing on A0
- void setup() {
- Wire.begin(I2C_ADDRESS);
- Wire.setClock(100000); //A Nunchuk's clock speed
- Wire.onRequest(requestEvent);
- }
- void loop(){
- //Nothing happening here
- }
- void requestEvent() {
- int ySpeed = map(analogRead(poti), 0, 1023, 0, 255); //Mapping the potentiometeres 0-1023 range to 0-255, which works with the Nunchuk input
- byte buffer[6] = {127, ySpeed, 0, 0, 0, 0}; //6 bits for X, Y (modified with poti as speed), the buttons and the accelerometer (as the hoverboard mainboard expects)
- Wire.write(buffer, 6); //Write to I2C
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement