• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Pomoc Arduino Uno R3
#10
Kod:
#include "UnoJoy.h"

void setup(){
setupPins();
setupUnoJoy();
}

void loop(){
// Always be getting fresh data
dataForController_t controllerData = getControllerData();
setControllerData(controllerData);
}

void setupPins(void){
// Set all the digital pins as inputs
// with the pull-up enabled, except for the
// two serial line pins
for (int i = 2; i <= 12; i++){
  pinMode(i, INPUT);
  digitalWrite(i, HIGH);
}
pinMode(A4, INPUT);
digitalWrite(A4, HIGH);
pinMode(A5, INPUT);
digitalWrite(A5, HIGH);
}

dataForController_t getControllerData(void){

// Set up a place for our controller data
//  Use the getBlankDataForController() function, since
//  just declaring a fresh dataForController_t tends
//  to get you one filled with junk from other, random
//  values that were in those memory locations before
dataForController_t controllerData = getBlankDataForController();
// Since our buttons are all held high and
//  pulled low when pressed, we use the "!"
//  operator to invert the readings from the pins
controllerData.triangleOn = !digitalRead(2);
controllerData.circleOn = !digitalRead(3);
controllerData.squareOn = !digitalRead(4);
controllerData.crossOn = !digitalRead(5);
controllerData.dpadUpOn = !digitalRead(6);
controllerData.dpadDownOn = !digitalRead(7);
controllerData.dpadLeftOn = !digitalRead(8);
controllerData.dpadRightOn = !digitalRead(9);
controllerData.l1On = !digitalRead(10);
controllerData.r1On = !digitalRead(11);
controllerData.selectOn = !digitalRead(12);
controllerData.startOn = !digitalRead(A4);
controllerData.homeOn = !digitalRead(A5);

// Set the analog sticks
//  Since analogRead(pin) returns a 10 bit value,
//  we need to perform a bit shift operation to
//  lose the 2 least significant bits and get an
//  8 bit number that we can use  
controllerData.leftStickX = analogRead(A0) >> 2;
controllerData.leftStickY = analogRead(A1) >> 2;
controllerData.rightStickX = analogRead(A2) >> 2;
controllerData.rightStickY = analogRead(A3) >> 2;
// And return the data!
return controllerData;
}


To jest prawidłowy kod
Jakbyś był tak dobry i poprawił mi ten kod Wink
 
  


Wiadomości w tym wątku
Pomoc Arduino Uno R3 - przez Hixi - 01-11-2017, 14:36
RE: Pomoc Arduino Uno R3 - przez krn78 - 02-11-2017, 12:12
RE: Pomoc Arduino Uno R3 - przez Hixi - 02-11-2017, 13:15
RE: Pomoc Arduino Uno R3 - przez krn78 - 02-11-2017, 14:25
RE: Pomoc Arduino Uno R3 - przez Hixi - 02-11-2017, 21:39
RE: Pomoc Arduino Uno R3 - przez krn78 - 03-11-2017, 12:08
RE: Pomoc Arduino Uno R3 - przez Hixi - 03-11-2017, 15:08
RE: Pomoc Arduino Uno R3 - przez krn78 - 03-11-2017, 18:57
RE: Pomoc Arduino Uno R3 - przez Hixi - 05-11-2017, 22:40
RE: Pomoc Arduino Uno R3 - przez Hixi - 05-11-2017, 23:02
RE: Pomoc Arduino Uno R3 - przez krn78 - 06-11-2017, 13:09
Pomoc Arduino Uno R3 - przez Hixi - 07-11-2017, 00:23
RE: Pomoc Arduino Uno R3 - przez PlusMinus - 07-11-2017, 09:26
RE: Pomoc Arduino Uno R3 - przez krn78 - 07-11-2017, 09:38
RE: Pomoc Arduino Uno R3 - przez PlusMinus - 07-11-2017, 10:23
Pomoc Arduino Uno R3 - przez Hixi - 07-11-2017, 16:35

Skocz do:


Przeglądający: 1 gości