ayush3504 icon

Untitled

ayush3504 | PRO | 07/14/14 11:08:49 PM UTC | 0 ⭐ | 368 👁️ | Never ⏰ | []
C |

890 B

|

None

|

0 👍

/

0 👎

/*
This code converts the byte received through the serial port to a PWM value in range 0-255. In this instance this serves as an interface between a PC and a camera AF coil. The necessary interface electronics need to be added as well.
The PWM frequency on most pins is ~490 Hz. However, it's ~980 Hz for pins 5 and 6 on the Uno, and for pins 3 and 11 on the Leonardo
 
Ayush Sagar
[email protected]
15 Jul 2014
*/
 
int coilPin = 11;           // the pin that the LED is attached to
byte value;
 
void setup() {
  //Set serial
  Serial.begin(9600);
  // Set coil pin to output
  pinMode(coilPin, OUTPUT);
}
 
// the loop routine runs over and over again forever:
void loop() {
  // if a byte is avalable in the serial receive buffer
  if (Serial.available() > 0){
 
    // pop byte from the buffer
    value = Serial.read();
 
    // set PWM
    analogWrite(coilPin, value);
  }  
}

Comments