Closed kvincn closed 11 months ago
Adafruit_ILI9341 LCD = Adafruit_ILI9341(TFT_CS, TFT_DC); NunchukController nunchukController; BulletList bulletList; Player player(120, 280, &LCD, &nunchukController, &bulletList); IR ir_comm;
void initADC() { ADMUX &= ~(1 << MUX0); ADMUX |= (1 << REFS0); ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); ADCSRA |= (1 << ADEN); }
void initPWM() { DDRD |= (1 << PD5);
TCCR1A |= (1 << COM1A1) | (1 << WGM10) | (1 << WGM11); TCCR1B |= (1 << CS10) | (1 << WGM12); OCR1A = 512;
}
void setup() { sei(); Serial.begin(9600); // Initialize Serial for debugging while (!Serial); // Wait for Serial to initialize
LCD.begin(); LCD.fillScreen(ILI9341_BLACK); LCD.setRotation(2); player.drawPlayer(); nunchukController.initialize(); ir_comm.IR_innit(); initADC(); initPWM(); // Timer0 setup for the ISR TCCR0A |= (1 << WGM01); TCCR0B |= (1 << CS02) | (1 << CS00); OCR0A = 156; // Set the value for the desired frequency (approx. 1 kHz) TIMSK0 |= (1 << OCIE0A); // Enable Timer0 Compare Match A interrupt
ISR(TIMER0_COMPA_vect){ PORTD ^= (1 << PORTD5); // Toggle pin 5 (for the ISR) here }
int main(void) { setup(); while (1) { player.controlPlayer(); bulletList.updateBullets();
ADCSRA |= (1 << ADSC); // Start ADC conversion while(ADCSRA & (1 << ADSC)); // Wait for conversion to complete uint16_t adcValue = ADC; // Read ADC value Serial.println(adcValue); // Print ADC value to Serial monitor for debugging OCR1A = adcValue * 4; // Convert ADC value to PWM value (0 - 1023) for brightness // _delay_ms(100); // Adjust delay if needed for ADC readings } return 0;
include
include
include
include
include <avr/io.h>
include <avr/interrupt.h>
include
include "classes/IR.h"
include "classes/Player.h"
include "classes/BulletList.h"
include "classes/NunchukController.h"
define TFT_CS 10
define TFT_DC 9
Adafruit_ILI9341 LCD = Adafruit_ILI9341(TFT_CS, TFT_DC); NunchukController nunchukController; BulletList bulletList; Player player(120, 280, &LCD, &nunchukController, &bulletList); IR ir_comm;
void initADC() { ADMUX &= ~(1 << MUX0); ADMUX |= (1 << REFS0); ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); ADCSRA |= (1 << ADEN); }
void initPWM() { DDRD |= (1 << PD5);
}
void setup() { sei(); Serial.begin(9600); // Initialize Serial for debugging while (!Serial); // Wait for Serial to initialize
}
ISR(TIMER0_COMPA_vect){ PORTD ^= (1 << PORTD5); // Toggle pin 5 (for the ISR) here }
int main(void) { setup(); while (1) { player.controlPlayer(); bulletList.updateBullets();
}