Of course. And using exactly the same method: serial communication. Since I'm not a big Windows expert, I can't write you a complete Windows example, but here are some snippets that can run you on Unix (Linux, OS X, etc.):
Arduino Code:
#define POT_PIN 1
void setup()
{
Serial.begin(9600);
}
void loop()
{
int pot = analogRead(POT_PIN);
unsigned char byte = (pot + 2) >> 2;
Serial.write(pot);
delay(100);
}
Computer code:
#include <termios.h>
struct termios tio;
memset(&tio, 0, sizeof(tio));
tio.c_cflag = CS8 | CREAD | CLOCAL;
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 5;
int fd = open(device, O_RDONLY);
cfsetospeed(&tio, B9600);
cfsetispeed(&tio, B9600);
tcsetattr(fd, TCSANOW, &tio);
while (1) {
unsigned char byte;
read(fd, &byte, 1);
use_some_library_to_set_volume(byte);
}
user529758
source
share