Created
August 24, 2012 01:10
-
-
Save ptweir/3444320 to your computer and use it in GitHub Desktop.
Arduino code to control polarization rotator (switcher) based on USB commands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// polarization rotator experiment | |
int incomingByte = 1; // for incoming serial data | |
int pwmPin = 9; // white wire | |
int dirPin = 11; // green wire | |
int statusLED = 13; | |
int delaymsec = 100; | |
void setup() { | |
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps | |
// initialize pwm and dir pins as outputs. | |
pinMode(pwmPin, OUTPUT); | |
pinMode(dirPin, OUTPUT); | |
pinMode(statusLED, OUTPUT); // status LED | |
} | |
void loop() { | |
// check for incoming serial data: | |
if (Serial.available() > 0) { | |
// read the incoming byte: | |
incomingByte = int(Serial.read()) - 48; | |
} | |
if (incomingByte == 1) { | |
//volage-state ON, polarization NOT rotated, status LED ON | |
digitalWrite(statusLED,HIGH); | |
digitalWrite(pwmPin, HIGH); | |
analogWrite(dirPin, 127); | |
delay(delaymsec); | |
} | |
if (incomingByte == 2) { | |
//volage-state OFF, polarization IS rotated, status LED OFF | |
digitalWrite(statusLED,LOW); | |
digitalWrite(pwmPin, LOW); | |
analogWrite(dirPin, LOW); | |
delay(delaymsec); | |
} | |
incomingByte = 0; // no new data, skip all updates | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment