arduino.digitalWrite() is acting up.
in
Integration and Hardware
•
1 year ago
- import processing.serial.*;
- import procontroll.*;
- import net.java.games.input.*;
- import cc.arduino.*;
- Arduino arduino;
- ControllIO controll;
- ControllDevice joystick;
- ControllSlider XAxis;
- ControllSlider YAxis;
- ControllSlider Rotation;
- ControllSlider Slider1;
- ControllSlider Slider2;
- ControllCoolieHat CoolieHat;
- int ArmSpeed = 100; //From 0 to 255
- void setup() {
- size(500, 500);
- println(Arduino.list());
- arduino = new Arduino(this, Arduino.list()[1], 57600);
- for (int i = 2; i <= 13; i++)
- arduino.pinMode(i, Arduino.OUTPUT);
- controll = ControllIO.getInstance(this);
- controll.printDevices();
- joystick = controll.getDevice("Cyborg F.L.Y.5 Flight Stick");
- YAxis = joystick.getSlider(0);
- XAxis = joystick.getSlider(1);
- Rotation = joystick.getSlider(2);
- Slider1 = joystick.getSlider(3);
- Slider2 = joystick.getSlider(4);
- YAxis.setTolerance(0.11);
- XAxis.setTolerance(0.11);
- Rotation.setTolerance(0.01);
- // Slider1.setTolerance(0.01);
- // Slider2.setTolerance(0.01);
- YAxis.setMultiplier(100);
- XAxis.setMultiplier(100);
- background(255);
- arduino.digitalWrite(13, Arduino.HIGH);
- }
- float R = 0;
- float L = 0;
- float Z;
- void getJoy(){
- float X = XAxis.getValue();
- float Y = YAxis.getValue();
- float V = (100 - abs(X)) * (Y/100) + Y;
- float W = (100 - abs(Y)) * (X/100) + X;
- R = (V + W)/2;
- L = (V - W)/2;
- R = -R;
- L = -L;
- Z = ((Slider2.getValue() + Slider1.getValue())/2);
- }
- void drawGraph(){
- background(255);
- rect(50, height / 2, 25, -R);
- rect(100, height / 2, 25, -L);
- rect(150, height / 2, 25, Z * 100);
- }
- void draw() {
- getJoy();
- //println("R: " + R + " L: "+ L + " Z: " + Z);
- CoolieHat = joystick.getCoolieHat(14);
- // println("X: " + CoolieHat.getX() + " Y: " + CoolieHat.getY());
- fill(150);
- stroke(0);
- drawGraph(); //Left Motors pin 2/3, R (4/5), Z (7/6), ARM(8/9)
- if (L >= 0){
- arduino.digitalWrite(2, Arduino.HIGH);
- } else {
- arduino.digitalWrite(2, Arduino.LOW);
- }
- arduino.analogWrite(3, round((L/100)*255));
- if (R >= 0){
- arduino.digitalWrite(4, Arduino.HIGH);
- } else {
- arduino.digitalWrite(4, Arduino.LOW);
- }
- arduino.analogWrite(5, round((R/100)*255));
- if (Z >= 0){
- arduino.digitalWrite(7, Arduino.HIGH);
- } else {
- arduino.digitalWrite(7, Arduino.LOW);
- }
- delay(100);
- arduino.analogWrite(6, round(Z*255));
- delay(100);
- arduino.digitalWrite(13, Arduino.HIGH);
- }
My voltmeter reads 0.02 volts on that pin regardless of what I'm doing, but if I run the standard firmata.exe, it all works fine.
Furthermore, voltage on pin 2 fluctuates from 0.95 to 4.8 (Using a standard DMM, no Oscilloscope around) when set to HIGH, but when set to LOW, it gives ground like expected.
Is there anything obvious I'm doing wrong?
1