Pomoc Arduino Uno R3 - Hixi - 01-11-2017
Witam,
Jestem nowy. Potrzebuję pomocy w kodzie sketch-u. W tym kodzie potrzebuję aby zamiast 1 potencjometru podłączyć 1 przycisk czy jest taka możliwość? na tym kodzie mogę zaprogramować 13 przycisków a potrzebuję 14 :
Kod: #include <Bridge.h>
#include <BridgeClient.h>
#include <BridgeServer.h>
#include <BridgeSSLClient.h>
#include <BridgeUdp.h>
#include <Console.h>
#include <FileIO.h>
#include <HttpClient.h>
#include <Mailbox.h>
#include <Process.h>
#include <YunClient.h>
#include <YunServer.h>
#include <Keypad.h>
#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;
}
RE: Pomoc Arduino Uno R3 - krn78 - 02-11-2017
Podłącz przycisk zamiast potencjometru, napisz nowy program, który wyświetla na monitorze szeregowym stan przycisku wciśniętego i puszczonego. Będziesz miał odpowiedź, czy się da, i co z tego wynika. Potem już tylko będziesz musiał uwzględnić to w programie.
RE: Pomoc Arduino Uno R3 - Hixi - 02-11-2017
(02-11-2017, 12:12)krn78 napisał(a): Podłącz przycisk zamiast potencjometru, napisz nowy program, który wyświetla na monitorze szeregowym stan przycisku wciśniętego i puszczonego. Będziesz miał odpowiedź, czy się da, i co z tego wynika. Potem już tylko będziesz musiał uwzględnić to w programie.
Hmmm jak pisałem jestem początkujący i nie wiem za bardzo jak zmienić kod z pota na przycisk..
RE: Pomoc Arduino Uno R3 - krn78 - 02-11-2017
Na początek nie zmieniaj niczego Podłącz go tylko pod ten sam pin i sprawdź odczyty.
RE: Pomoc Arduino Uno R3 - Hixi - 02-11-2017
(02-11-2017, 14:25)krn78 napisał(a): Na początek nie zmieniaj niczego Podłącz go tylko pod ten sam pin i sprawdź odczyty.
Kurde podłączyłem i dupa nic sie nie dzieje ;/
RE: Pomoc Arduino Uno R3 - krn78 - 03-11-2017
Hmmm... pewnie coś poszło nie tak. Podłącz przycisk pod A0, z drugiej strony przycisku zasilanie.
Kod: void setup(){
Serial.begin(9600);
}
void loop()
Serial.println(analogRead(A0));
delay(500);
}
Złóż układ, wklej kod, uruchom, włącz monitor, baw się całością i obserwuj efekt. Będziesz wiedział, jak zastosować taki układ w swoim programie.
RE: Pomoc Arduino Uno R3 - Hixi - 03-11-2017
(03-11-2017, 12:08)krn78 napisał(a): Hmmm... pewnie coś poszło nie tak. Podłącz przycisk pod A0, z drugiej strony przycisku zasilanie.
Kod: void setup(){
Serial.begin(9600);
}
void loop()
Serial.println(analogRead(A0));
delay(500);
}
Złóż układ, wklej kod, uruchom, włącz monitor, baw się całością i obserwuj efekt. Będziesz wiedział, jak zastosować taki układ w swoim programie.
Dzięki za info Będę kombinował jak to połączyć żeby mieć wszystkie dostępne przyciski.
Po wgraniu sketch programuję tak aby arduino było wyszukane p&p na kompie do którego się podłączy
RE: Pomoc Arduino Uno R3 - krn78 - 03-11-2017
(03-11-2017, 15:08)Hixi napisał(a): Dzięki za info Będę kombinował jak to połączyć żeby mieć wszystkie dostępne przyciski.
Po wgraniu sketch programuję tak aby arduino było wyszukane p&p na kompie do którego się podłączy
Mniemam, że działa. Teraz tylko pozostaje Ci zastosować to do Twojego przykładu. Rozwiązań jest kilka :eśli będziesz mieć problem, pytaj.
RE: Pomoc Arduino Uno R3 - Hixi - 05-11-2017
(03-11-2017, 18:57)krn78 napisał(a): (03-11-2017, 15:08)Hixi napisał(a): Dzięki za info Będę kombinował jak to połączyć żeby mieć wszystkie dostępne przyciski.
Po wgraniu sketch programuję tak aby arduino było wyszukane p&p na kompie do którego się podłączy
Mniemam, że działa. Teraz tylko pozostaje Ci zastosować to do Twojego przykładu. Rozwiązań jest kilka :eśli będziesz mieć problem, pytaj.
Tylko nie wiem właśnie jak do dograć do tego kodu co już posiadam...
RE: Pomoc Arduino Uno R3 - Hixi - 05-11-2017
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
|