Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Warning! THIS CODE WILL HEAT UP YOUR TESLA COIL VERY QUICKLY!!! USE IT AT YOUR OWN RISK!!!
- int duty;
- int raw;
- int state = 0;
- void setup(){
- TCCR1B = 0x01;//sets frequency to 32khz
- // ADC Boost Start - sets ADC clock to 1MHz
- // defines for setting and clearing register bits
- #ifndef cbi
- #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
- #endif
- #ifndef sbi
- #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
- #endif
- // set ADC prescaler to 16
- sbi(ADCSRA,ADPS2) ;
- cbi(ADCSRA,ADPS1) ;
- cbi(ADCSRA,ADPS0) ;
- // ADC Boost End
- }
- void loop(){
- raw = analogRead (3);
- //limit maximum power
- if (raw > 40){
- raw =40;
- }
- //reduces frequency from 32khz to 16khz
- if (state == 0){
- state =1;
- }else{
- state = 0;
- raw = 0;
- }
- //creates the pwm signal
- duty = raw/8;
- analogWrite(9, duty);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement