Advertisement
Guest User

Untitled

a guest
May 27th, 2018
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <Wire.h>
  2.  
  3. const uint8_t I2C_ADDRESS = 0x52; //The original Nunchuk's I2C address
  4.  
  5. int poti = 0; //Potentiometer for testing on A0
  6.  
  7. void setup() {
  8.   Wire.begin(I2C_ADDRESS);
  9.   Wire.setClock(100000); //A Nunchuk's clock speed
  10.   Wire.onRequest(requestEvent);
  11. }
  12.  
  13. void loop(){
  14.   //Nothing happening here
  15. }
  16.  
  17. void requestEvent() {
  18.   int ySpeed = map(analogRead(poti), 0, 1023, 0, 255); //Mapping the potentiometeres 0-1023 range to 0-255, which works with the Nunchuk input
  19.   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)
  20.   Wire.write(buffer, 6); //Write to I2C
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement