Tricka90
Member level 1
- Joined
- Sep 2, 2013
- Messages
- 40
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 8
- Activity points
- 385
Sound_Play(523,600);
Sound_Play(262,200);
Sound_Play(349,400);
Sound_Play(523,600);
Sound_Play(262,200);
Sound_Play(294,200);
Sound_Play(349,200);
Sound_Play(523,200);
Sound_Play(349,200);
Sound_Play(294,400);
Sound_Play(523,600);
Sound_Play(233,200);
Sound_Play(349,400);
Sound_Play(466,600);
Sound_Play(349,200);
Sound_Play(233,400);
Sound_Play(440,200);
Sound_Play(349,200);
Sound_Play(233,400);
Sound_Play(440,1400);
Delay_ms(1000);
Code C - [expand] 1 while(1);
long intro;
while(intro <= 100000) {intro++;}
void main();
//VARIABLES
int red = 20;
int blue = 20;
int green = 20;
int adc = 0;
int stato = 0;
int mode_change = 0;
int colore = 0;
int clockON = 0;
int pwm_rgb = 0;
int mode = 1;
int j = 0;
int pwm = 0;
int flash = 0;
int lum = 20;
int lum_provv;
int clock = 0;
unsigned long intro = 0;
void interrupt()
{
if (INTCON.TMR0IF)
{
if(mode == 5) {
j++;
if(j >= flash*30+80)
{
if(pwm == 1)
{
lum_provv = lum;
lum=0;
pwm = 0;
}
else
{
lum = lum_provv;
pwm = 1;
}
j = 0;
}
}
if(pwm_rgb >= 20)
{
pwm_rgb = 0;
}
else
{
pwm_rgb++;
}
if(green >= pwm_rgb && green != 0)
{
PORTB.RB1 = 1;
}
else
{
PORTB.RB1 = 0;
}
if(red >= pwm_rgb && red != 0)
{
PORTB.RB0 = 1;
}
else
{
PORTB.RB0 = 0;
}
if(blue >= pwm_rgb && blue != 0)
{
PORTB.RB2 = 1;
}
else
{
PORTB.RB2 = 0;
}
INTCON.TMR0IF = 0;
}
}
void melody()
{
Sound_Play(523,600);
Sound_Play(262,200);
Sound_Play(349,400);
Sound_Play(523,600);
Sound_Play(262,200);
Sound_Play(294,200);
Sound_Play(349,200);
Sound_Play(523,200);
Sound_Play(349,200);
Sound_Play(294,400);
Sound_Play(523,600);
Sound_Play(233,200);
Sound_Play(349,400);
Sound_Play(466,600);
Sound_Play(349,200);
Sound_Play(233,400);
Sound_Play(440,200);
Sound_Play(349,200);
Sound_Play(233,400);
Sound_Play(440,1400);
Delay_ms(1000);
}
int RGB(int adc, int i) {
if(adc >= 210) {
if(adc <= 280) { Delay_ms(80); adc = ADC_Read(0); if(adc <= 290 && adc >= 220) {
mode_change = 0;
stato = 0;
{ PORTC.RC3 = 0; PORTC.RC4 = 0; PORTC.RC5 = 1; }
i = i-1;
if(i <= 0){ i = 0;
Sound_Play(659, 20); }
Sound_Play(523, 20);
}}
else {
if(adc >= 940) {
{ PORTC.RC3 = 0; PORTC.RC4 = 1; PORTC.RC5 = 0; }
i = i+1;
if(i >= 20){ i = 20; Sound_Play(1319, 20); }
Sound_Play(1046, 20);
Delay_ms(80);
}
if(adc <= 840 && adc >= 320) {
{ PORTC.RC3 = 1; PORTC.RC4 = 0; PORTC.RC5 = 0; stato = 1; }
i = i;
}
}
}
if(adc <= 170)
{
{ PORTC.RC3 = 0; PORTC.RC4 = 0; PORTC.RC5 = 0; }
if(stato == 1)
{
mode_change++;
}
if(mode_change == 1)
{
clockON = 1;
}
stato = 0;
}
colore = i;
return(colore);
}
void main()
{
ADCON0 = 0;
ADCON1 = 0b00001110;
//TRIS
{
TRISB = 0;
PORTB = 0;
TRISC = 0;
PORTC = 0;
TRISA = 0b00000001;
PORTA = 0;
PORTA.RA2 = 1;
}
Sound_Init(&PORTA, 1);
//INTRO MUSIC
melody();
//CCP_PWM (RC2, RC1)
{
PWM1_Init(5500);
PWM1_Set_Duty(210);
PWM1_Start();
PWM2_Init(1000);
PWM2_Set_Duty(lum*12+10);
PWM2_Start();
}
//TIMER/INTERRUPT
{
OPTION_REG = 0b10000010;
INTCON = 0b11100000;
}
while(1)
{
adc = ADC_Read(0);
if(clockON == 1)
{
clock++;
if(clock >= 6500)
{
if(mode_change >= 2) { if(mode_change <= 4)
{
if(mode_change == 2) {
mode++;
if(mode == 6)
{
mode = 1;
}
}
if(mode_change == 3 || mode_change == 4)
{
mode -= 1;
if(mode == 0)
{
mode = 5;
}
}
if(mode == 4)
{
PORTB.RB4= 1;
PORTA.RA5= 0;
PORTB.RB5= 0;
}
if(mode == 5)
{
PORTA.RA2= 0;
PORTB.RB4= 0;
PORTB.RB5= 1;
}
if(mode == 1)
{
PORTA.RA2= 1;
PORTA.RA3= 0;
PORTB.RB5= 0;
}
if(mode == 2)
{
PORTA.RA2= 0;
PORTA.RA3= 1;
PORTA.RA5= 0;
}
if(mode == 3)
{
PORTA.RA5= 1;
PORTA.RA3= 0;
PORTB.RB4= 0;
}
mode_change = 0;
Delay_ms(50);
Sound_Play(1046, 60);
Delay_ms(15);
Sound_Play(1568, 60);
Delay_ms(15);
Sound_Play(1046, 60);
Delay_ms(700);
}}
mode_change = 0;
clock = 0;
clockON = 0;
}
}
switch(mode) {
case 1:
RGB(adc, lum);
lum = colore;
PWM2_Set_Duty(lum*12+10);
break;
case 2:
RGB(adc, blue);
blue = colore;
break;
case 3:
RGB(adc, green);
green = colore;
break;
case 4:
RGB(adc, red);
red = colore;
break;
case 5:
RGB(adc, flash);
flash = colore;
PWM2_Set_Duty(lum*12+10);
break;
}
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?