Terrificten

Higher quality tesla coil interrupter arduino code

May 22nd, 2019
206
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Warning! THIS CODE WILL HEAT UP YOUR TESLA COIL VERY QUICKLY!!! USE IT AT YOUR OWN RISK!!!
  2. int duty;
  3. int raw;
  4. int state = 0;
  5. void setup(){
  6. TCCR1B = 0x01;//sets frequency to 32khz
  7.  
  8. // ADC Boost Start - sets ADC clock to 1MHz
  9. // defines for setting and clearing register bits
  10.  
  11. #ifndef cbi
  12. #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
  13. #endif
  14. #ifndef sbi
  15. #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
  16. #endif
  17.  
  18. // set ADC prescaler to 16
  19. sbi(ADCSRA,ADPS2) ;
  20. cbi(ADCSRA,ADPS1) ;
  21. cbi(ADCSRA,ADPS0) ;
  22. // ADC Boost End
  23.  
  24. }
  25.  
  26. void loop(){
  27. raw = analogRead (3);
  28. //limit maximum power
  29. if (raw > 40){
  30. raw =40;
  31. }
  32. //reduces frequency from 32khz to 16khz
  33. if (state == 0){
  34. state =1;
  35. }else{
  36. state = 0;
  37. raw = 0;
  38. }
  39. //creates the pwm signal
  40. duty = raw/8;
  41. analogWrite(9, duty);
  42.  
  43. }
RAW Paste Data