ayush3504

Untitled

Jul 14th, 2014
279
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. 15 Jul 2014
  7. */
  8.  
  9. int coilPin = 11;           // the pin that the LED is attached to
  10. byte value;
  11.  
  12. void setup() {
  13.   //Set serial
  14.   Serial.begin(9600);
  15.   // Set coil pin to output
  16.   pinMode(coilPin, OUTPUT);
  17. }
  18.  
  19. // the loop routine runs over and over again forever:
  20. void loop() {
  21.   // if a byte is avalable in the serial receive buffer
  22.   if (Serial.available() > 0){
  23.  
  24.     // pop byte from the buffer
  25.     value = Serial.read();
  26.  
  27.     // set PWM
  28.     analogWrite(coilPin, value);
  29.   }  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment