We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, so this is my code so far and all works well. However i would like to use 3 hotkeys to change the colour than mouse position.
Anyone know how i can do this?
Thanks
Processing code
import processing.serial.*;
Serial port;
int c;
void setup() {
size(300, 150);
// println("Available serial ports:");
// println(Serial.list());
port = new Serial(this, "/dev/cu.usbmodem1421", 9600);
c = 2;
}
void draw() {
background(255);
line(100, 0, 100, height);
line(200, 0, 200, height);
// write the current X-position of the mouse to the serial port as
// a single byte
int newc = int(1 + mouseX/100);
if (newc != c) {
c = newc;
println(">> " + c); // DEBUG
port.write("" + c);
}
}
Arduino code
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TFT_SCLK 13
#define TFT_MOSI 11
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
void setup(void) {
Serial.begin(9600);
tft.initR(INITR_144GREENTAB);
tft.fillScreen(ST7735_BLACK);
Serial.println("OK!");
}
void loop() {
tft.invertDisplay(false);
if (Serial.available()) {
byte c = Serial.read();
if (c == '1') {
testdrawrects(ST7735_GREEN);
} else if (c == '2') {
testdrawrects(ST7735_WHITE);
} else if (c == '3') {
testdrawrects(ST7735_RED);
}
Serial.println(c); // DEBUG
}
}
void testdrawrects(uint16_t color) {
// tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
}
}
Answers
I may guess that you need to only change processing part like this (not tested):