A little background... I've just started in the world of circuits and have made it through most of the Experimentation Kit sample circuits to get my feet wet. I have a background in programming software.
My first project is fairly simple and a little silly. Basically I want to turn on / off a vintage stereo receiver using Arduino by sending serial commands from my mac mini media center. So far I have everything working on the Arduino side but am having trouble now that I'm trying to send the serial data.
Here is the Arduino sketch:
Code: Select all
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// variables
int pos = 0;
int onOff = 0;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop()
{
// send data only when you receive data:
//if (Serial.available() > 0) {
// read the incoming byte:
onOff = Serial.read();
// say what you got:
//Serial.print("I received: ");
//Serial.println(onOff, DEC);
if (onOff == 48)
{
turnOn();
}
else if (onOff == 49)
{
turnOff();
}
//}
}
void turnOn()
{
for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
void turnOff()
{
for(pos = 90; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Code: Select all
#!/usr/bin/env python
import time
import serial
ser = serial.Serial('/dev/tty.usbserial-A600af9G', 9600, timeout=1)
time.sleep(4.5)
ser.write('0')
I may be asking in the wrong forum but hope this is a good place to start.
Thanks,
Blake