i would like to drive with arrow keys, but can find very little documentation on this
and the code i did find didn't make sense to me.
Have you installed Processing? Have you looked at the zillions of examples? File + Examples... + Basics + Input + Keyboard, for instance.
Modify that to print the index of the key that was pressed. Then, when all you see is a ? for the arrow keys, select the function name (keyPressed) and select Find in Reference on the help menu.Look at the related links. keyCode, for instance. Print the keyCode, instead of the key.
What code was that?
import processing.serial.*;Serial myport;int val;void Setup(){ size(200,200); String portName = Serial.list()[4]; myport = new Serial(this, portName, 9600);}void draw() { background(255,255,0,255);}void keyPressed() { if (key == CODED){ if (key == UP) { myport.write('F'); } else if (key == DOWN){ myport.write('B'); } else if (key == LEFT){ myport.write('L'); } else if (key == RIGHT){ myport.write('R'); } else{ myport.write('S'); } }}
#include <Servo.h>Servo Left;Servo Right;//int Lspeed = 0;//int Rspeed = 0; int val; void setup() { Left.attach(12); Right.attach(13); Serial.begin(9600); } void loop() { if (Serial.available()) { val = Serial.read(); } if (val == 'F') { // If Forward command was received Left.write(180); // go forward Right.write(0); //invert direction for opposite motors } else if (val == 'B') { Left.write(0); Right.write(180); } else if (val == 'R') { Left.write(0); Right.write(0); } else if (val == 'L') { Left.write(180); Right.write(0); } else { Left.write(90); Right.write(90); } delay(100); // Wait 100 milliseconds for next reading }
should this work?
Exception in thread "Animation Thread" java.lang.NullPointerException at serial_control.keyPressed(serial_control.java:52) at processing.core.PApplet.handleKeyEvent(Unknown Source) at processing.core.PApplet.dequeueKeyEvents(Unknown Source) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PApplet.run(Unknown Source) at java.lang.Thread.run(Thread.java:662)
wow... 4 days and no reply? is this just some weird error that no one knows how to fix? what could I do to get around this error? thanks
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
Thank you for subscribing!
Arduino
via Egeo 16
Torino, 10131
Italy