Advertisement
ayush3504

Untitled

Jul 14th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. /*
  2. 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.
  3. 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
  4.  
  5. Ayush Sagar
  6. ayushsagar@gmail.com
  7. 15 Jul 2014
  8. */
  9.  
  10. int coilPin = 11;           // the pin that the LED is attached to
  11. byte value;
  12.  
  13. void setup() {
  14.   //Set serial
  15.   Serial.begin(9600);
  16.   // Set coil pin to output
  17.   pinMode(coilPin, OUTPUT);
  18. }
  19.  
  20. // the loop routine runs over and over again forever:
  21. void loop() {
  22.   // if a byte is avalable in the serial receive buffer
  23.   if (Serial.available() > 0){
  24.  
  25.     // pop byte from the buffer
  26.     value = Serial.read();
  27.  
  28.     // set PWM
  29.     analogWrite(coilPin, value);
  30.   }  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement