Timer

Glad to hear it, I was really confused as to why the chip would be playing at the wrong speed.

Anyway, I do run into error messages like that from time to time with the AVRISP mkII, I’m not really sure why. What programmer are you using again?

To initialize Timer0 on the ATMega168 you would just need to change a couple of the register names like this:

	TCNT0=~(124);//preload counter to overflow after 1 ms (125 counts)
	TIMSK0=(1<<TOIE0);//enable interrupt on timer0 overflow
	TCCR0B=(1<<CS01)|(1<<CS00);//set timer to normal mode with CPU clock/64 (125 kHz)

The ADC pins are the same on both the ATMega8 and ATMega168. The register bits are a little moved around, but your code might compile just fine as is. If you get errors (either in compiling or actual operation) post your ADC code here and we’ll have a looksey.

-Adam

Adam, I have everything working. Timers etc, etc. The only thing is that the set_track command isnt the one that decides which track plays. I see there is one called songs (which is the index of the track that is playing) which might be it, but couldnt get it to work? Please can you have a look. The set_track one always plays 0

Yeah, looking closer that doesn’t do at all what I thought it did. Try inserting this function instead:

void PlaySong(uint16 songs){
	uint16 keylen;			//ÓÃÓÚ¼ü´¦Àí		//for key processing
	uint16 count;			//Êý¾Ý¼ÆÊý			//data counting
	uint8 i;				//Ñ­»·±äÁ¿			//loop variable
	uint16 j;				//Ñ­»·±äÁ¿			//loop variable
	uint32 p;				//´Øָʾֵ			//cluster
	uint32 totalsect;		//ÎļþÓµÓеÄÉÈÇøÊý	//cotain the total sector number of a file
	uint16 leftbytes;		//Ê£Óà×Ö½Ú			//cotain the left bytes number of a file //the last cluster usually not fully occupied by the file
	uint8 *buffer;			//»º³å				//buffer
	uint32 sector;			//ÉÈÇø				//recor the current sector to judge the end sector
	uint8 flag;				//²¥·Å/ÔÝÍ£±êÖ¾		//flag of pause
	uint16 vol=DefaultVolume;//³õʼÒôÁ¿£¬Ó¦Óëvs1003º¯ÊýÀïµÄ³õʼÒôÁ¿Ïàͬ	//default volume
	uint8 mode=DEFAULT_MODE;//µ¥ÇúÖظ´			//repet all by default
	uint16 songs_cnt = 0;					//how many songs have been played
	if(totalsongs==0)return;//Èç¹ûûÓиèÇúÔòÒì³£Í˳ö	//if no music file return
	uint32 rand_val;
	Timer1_Initial();//Æô¶¯¶¨Ê±Æ÷£¬ÓÃÓÚ²úÉúËæ»úº¯ÊýµÄÖÖ×Ó	//initialize the timer
	ClearTrackInfo();
next://ÏÂÒ»Ê׸èµÄÆðʼµØ·½						//label for "goto"
	if(mode==RANDOM)//Ëæ»ú²¥·Å¸èÇú 				//if the mode is shuffle the songs
	{
		songs_cnt++;
		if(songs_cnt == totalsongs && totalsongs<1025)
		{
			ClearTrackInfo();
			songs_cnt = 0;
		}
		rand_val = TCNT1;
		Delay((random() && 0x00ff));
		rand_val <<= 16;
		rand_val += TCNT1;
		srandom(rand_val);
		if(totalsongs>1024)
		{
			songs = (uint16)(((random()/214749)*(uint32)totalsongs)/10000)+1;//Ëæ»ú²úÉú¸èÇúÐòºÅ	//create random song number
		}
		while(totalsongs<1025)
		{
			songs = (uint16)(((random()/214749)*(uint32)totalsongs)/10000)+1;//Ëæ»ú²úÉú¸èÇúÐòºÅ	//create random song number
			if(SetTrack(songs) == 0)break;
		}	
	}
	count=0;//Çå»ùÊý	//clear count
	flag=1;
	while(count<2048 && (type != MID))//recommand 2048 zeros honoring DREQ befor soft reset
	{									//ÓÃÓÚ´ÓwmaÌø³öµ½ÏÂÒ»Ê׸裬ºÍÒ»Ê׸è½áÊøÌî³äÊý¾Ý//midi¸ñʽ²»ÐèÒª
		if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0)
		{
			for(j=0;j<32;j++)
			{
				VS1003B_WriteDAT(0x00);//Ìî³ä0	//fill 0
				count++;
			}
			if(count == 2047)break;
		}
	}
	VS1003B_SoftReset();//soft reset //in case of playing wma files//Èí¼þ¸´Î»
	Search(PATH,&MusicInfo,&songs,&type);		//ÕÒµ½ÏàÓ¦µÄÎļþ		//find the file
	p     = MusicInfo.deStartCluster+(((uint32)MusicInfo.deHighClust)<<16);//¶ÁÎļþÊ×´Ø	//the first cluster of the file
		
	totalsect = MusicInfo.deFileSize/512; //¼ÆËãÉÈÇøÊý			//calculate the total sectors
	leftbytes = MusicInfo.deFileSize%512; //¼ÆËãÊ£ÓàµÄ×Ö½ÚÊý	//calculate the left bytes	
	i=0;
	sector=0;
	
	while(1)
	{
		keylen=0;
    	for(;i<SectorsPerClust;i++)		//Ò»¸ö´Ø	//a cluster
		{
			buffer=malloc(512);
			FAT_LoadPartCluster(p,i,buffer);//¶ÁÒ»¸öÉÈÇø	//read a sector
			count=0;
			while(count<512)
			{
				if(flag==0){if(keylen){Delay(100);keylen--;}}
				else if(type == MID){if(keylen){Delay(100);keylen--;}}
				if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 && flag)	//¸ù¾ÝÐèÒªËÍÊý¾Ý  //send data  honoring DREQ
				{
					for(j=0;j<32;j++)			//ÿ´ÎËÍ32¸öÊý¾Ý		//32 Bytes each time
					{
						VS1003B_WriteDAT(buffer[count]);
						count++;
					}
					if(keylen)keylen--;			//ÓÃÓÚ¼ü´¦Àí			//for key processing
					if(sector == totalsect && count >= leftbytes)		//Èç¹ûÎļþÒѽáÊø		//if this is the end of the file
					{
						if(type == MID)//waiting the midi file was decoded
						{//¶ÔÓÚmidÒôÀÖÒª½Ó×ÅËÍ2048¸öÁã
							count=0;
							while(count<2048)//recommand 2048 zeros honoring DREQ goto next songs
							{
								if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 )
								{
									for(j=0;j<32;j++)
									{
										VS1003B_WriteDAT(0x00);
										count++;
									}
									if(count == 2047)break;
								}
							}
						}
						i=SectorsPerClust;
						break;
					}//Îļþ½áÊø			//file ended
					if(count == 511){break;}//512×Ö½ÚËÍÍêÌø³ö		//break if a sector was sent
				}
				if((PIND&STOP)==0 /*&& keylen==0*/)//²¥·ÅÔÝÍ£¼ü		//key PLAY/PAUSE
			    {
	 			    Delay(100);
					if(!(PIND&STOP))
					{
						while(!(PIND&STOP));
						 if(flag)flag=0;
						 else flag=1;
						 Delay(1000);
					 }
				 }
				else if(!(PIND&DOWN) && keylen==0)  //ÒôÁ¿-			//Volume down
	 			{
				    Delay(100);
	   			 	if(!(PIND&DOWN))  
					{
					keylen=200;
					   vol=vol+((uint16)(1<<8)+1);
					   if(vol>=0xFEFE) vol=0xFEFE; 
	   			       else VS1003B_WriteCMD(0x0b,vol);
					 }
	 			 }
				 else if(!(PIND&UP) && keylen==0) //ÒôÁ¿+			//Volume up
	  			 {
					 Delay(100);
				 	 if(!(PIND&UP)) 
					 {
					 keylen=200;
					   vol=vol-((uint16)(1<<8)+1);
					   if(vol<=0x0101) vol=0x0101;
					   else VS1003B_WriteCMD(0x0b,vol);
	   			     }
				  }
				 else if(!(PIND&NEXT)) //ÏÂÒ»Ê×						next songs
	 			 {
					Delay(0x7fff);		
					if(!(PIND&NEXT))
					{
						Delay(0x7fff);
						if(!(PIND&NEXT))
						{
							while(!(PIND&NEXT));
							songs++;
							if(songs > totalsongs)songs=1;
							{
								free(buffer);
							//	Delay(0xffff);
								goto next;
							}
						}
					}
	  			 }
				 else if(!(PIND&PREV)) //ÉÏÒ»Ê×						previous songs
	 			 {
					Delay(0x7fff);		
					if(!(PIND&PREV))
					{
						Delay(0x7fff);
						if(!(PIND&PREV))
						{
							while(!(PIND&PREV));
							if(songs == 1)songs=totalsongs;
							else songs--;
							{
								free(buffer);
							//	Delay(0xffff);
								goto next;
							}
						}
					}
	  			 }
				 else if((!(PIND&MODE)) && keylen==0) //ģʽ			//mode key
	 			 {
					Delay(100);		
					if(!(PIND&MODE))
					{
						keylen=0xffff;
						if(mode==REPET_ALL)
						{
							mode=REPET_ONE;
							LED1_ON();
							LED2_OFF();
						}
						else if(mode==REPET_ONE)//next mode is shuffle
						{
							mode=RANDOM;
							LED1_OFF();
							LED2_ON();
							srandom(((uint32)TCNT1)<<16);//²úÉúËæ»úÊýµÄÖÖ×Ó
						}
						else 
						{
							mode=REPET_ALL;
							LED1_OFF();
							LED2_OFF();
						}
					}
	  			 }
			}
			sector++;
			free(buffer);
		}
	}
}

It’s a very slightly altered version of PlayMusic() (with a lot of extra unnecessary stuff still in it) but I think it will play the song number you feed it then return when the track is done.

-Adam

so do i call the function playmusic(single_zero_wheel[pot_idx])?

and that will input the right number into play music?

I’ll try and go through your function removing the other stuff…

I would add this new function, ‘PlaySong()’, into the code you have already, somewhere above the main function (you don’t need to do anything to the existing ‘PlayMusic()’ function).

Then you should be able to call PlaySong(single_zero_wheel[pot_idx]), it should play the correct track only once, and the function should return when the track is done playing. I think…

-Adam

Ahh right, i didnt notiuce the difference between names… I give that a go

Cheers

I am going to try that tonight, my house doesnt have internet so i couldnt download your new function…

Quick question, do you know how i would ammend a text file on the sd card. What i want to do is to store the values of pot_idx that get spoken by the program, so i can look at them on computer later…?

Any ideas?

Thanks

Alex

Reading/Writing to an SD card over an SPI interface is something I want to figure out at some point, but I haven’t played around with it yet, and the code you’re using seems to only have “read” functions. Writing is a little more complicated, since in addition to writing the actual bytes, you need to edit size and location information about the file as well. If you figure out how to do it though, you should totally post it here!

-Adam

Firstly, I have installed that function you gave me and it works, to a certain extent. I can move the sliding potentiometer, and when i press the button it always says number 7. I tried the same code on the orangutan, and it works there, the only line being changed is one from print to lcd, to the other saying say the number that the sliding pot is on.

This makes me think that i havent initiated the correct adc pin. My sliding pot is on pin 27 and my adc initiation code is:

//-----------------------------------------
        //All to do with ADC......................
        //-----------------------------------------
void analog_init(void)
{

ADMUX = (1 << REFS0);

ADCSRA = (6 << ADPS0);


ADCSRA |= (1 << ADEN);
}

unsigned int analog10(unsigned char channel)
{

ADMUX &= ~0x1F;

ADMUX |= channel;

ADCSRA |= (1 << ADSC);

while (bit_is_set(ADCSRA, ADSC));


return (ADCL | ADCH << 4); // read ADC (full 10 bits);
}

unsigned int analog8(unsigned char channel)
{
return(analog10(channel) >> 2);
}
		//-----------------------------------------
        //Finish - All to do with ADC......................
        //-----------------------------------------

Is it reading from the right pin?

The functin for taking the adc value is:

int wheel(void){
   wheel_ms1 = 0; 
   wheel_ms1 = 0;

   
    while (PIND&(1<<PD7));  // loop here until first button press
    TCNT0 = 0;
    timer_tick_wheel=0;// here is where we start timing
    _delay_ms(1);  // delay for 1 ms to debounce button press

    while (!(PIND&(1<<PD7)));  // loop here until button is released
    _delay_ms(10);  // delay for 10 ms to debounce button release
   
   
    while (PIND&(1<<PD7));  // loop here until second button press
    wheel_ms1 = timer_tick_wheel;      //get the value of the millisecond counter
     timer_tick_wheel=0;// here is where reset the timer
    _delay_ms(1);  // delay for 1 ms to debounce button press
       
    while (!(PIND&(1<<PD7)));  // loop here until button is released
   
    _delay_ms(10);  // delay for 10 ms to debounce button release
   
    while (PIND&(1<<PD7));  // loop here until 3rd button press
    wheel_ms2 = timer_tick_wheel;      //get the value of the millisecond counter
   
//    lcd_line1();// display the times
  //  lcd_time(wheel_ms1);
    //lcd_line2();
    //lcd_time(wheel_ms2);
PlaySong(wheel_ms2);
 _delay_ms(1000);  
   //lcd_clear();
	main();
return(0);
}

but i cant get it to go back to the main function at the end, even though main is there…

I have found a good project on avr freaks for writing to the sd card, but havent been able to totally disect it for the bits i;m interested in yet…

avrfreaks.net/index.php?modu … pe=project

Alex

Maybe I’m remembering wrong, but are you using the built-in potentiometer on your Orangutan? That’s wired to a dedicated ADC pin, ADC7 (which is why you would use the command “analog8(7)” to check it). The DIP package ATMega8 and ATMega168 have fewer pins, and they don’t actually bring out these dedicated ADC pins for you to use. Pin 27 on the DIP package ATMega168 is PC4, which is also ADC4, so you would check it by calling analog8(4).

I don’t see where you’re calling the analog checking functions (analog8 or analog10) in the code you posted, actually it looks like the song is being determined by the stopwatch lap time stored in wheel_ms2. Anyway, in general you don’t want to call the main function to get back to it, since this will run the function from the beginning again, and rerun all of your initialization functions (which only need to run once). The big problem with doing this is that it leads to loops of functions calling each other back and forth, which will eventually fill up your ram and cause problems. If you leave out the “main()” call, the next line “return 0” will dump your code back to the function that called it, which in your case is probably the main function.

-Adam

P.S. Thanks for the link by the way, I’ll take a look at that project at some point. It looks similar to the functionality of the SparkFun Logomatic, which has served me well (if only it operated at +5V!). Looks like this one only writes though, so if you combine it with your current project that only reads you’ll have the complete package!

Yeah I cant see in my code where i call the adc pin??? Where should i be calling the adc pin? Somewhere i must be because it came straight out of the orangutan, and that works!

I have been using a slide pot on the orangutan - adc7 of the orangutan…

Will have proper look at that link, thats going to be quite alot of disecting to get what im after!

If you can’t find it, you could post your complete current code.

-Adam

Cheers Adam

Its long… Here goes.

/*******************************************************************/
/*          Mega8 MP3 Player (mega8 + VS1003 + SD)  V1.8           */
/*                                                                 */
/* Discription: Can play mp3/wma/wav/mid SF0 files in the root     */
/*              directery on the SD card which file system is FAT16*/
/*              or FAT32.                                          */
/*              It has six keys to control this player             */
/*              MODE: switch between repeat all (default),repeat 1 */
/*                    and shuffle                                  */
/*              PLAY/PAUSE:                                        */
/*              PREV: previous songs                               */
/*              NEXT: next songs                                   */
/*              UP  : volume up                                    */
/*              DOWN: volume down                                  */
/* Platform   : AVRStudio4.13 b528 + WinAVR20070525                */
/*              optimize -0s                                       */
/* Author     : bozai(Zhang Qibo)                                  */
/* E-mail     : sudazqb@163.com                                    */
/* MSN        : zhangqibo_1985@hotmail.com                         */
/* Date       : 2007-06-16                                         */
/*******************************************************************/
/*  V1.8                                                           */
/*  2007-06-16                                                     */
/*  Still the bug of FAT, it's not resolved totally                */
/*                                                                 */
/*  V1.7                                                           */
/*  2007-05-21                                                     */
/*  Fix a serious bug of FAT                                       */
/*  Set the default mode to "Shuffle"                              */
/*  Because the mode button is inside the box                      */
/*  So I don't want to open the box when I turn on it              */
/*  If the button is easy to press of your mp3 player              */
/*  just change the macro below to:                                */
/*            0 = repet all    1 = repet one  2 = shuffle          */

#define DEFAULT_MODE   0

/*                                                                 */
/*  V1.6                                                           */
/*  2007-05-09                                                     */
/*  And a track function to make the shuffle a real shuffle        */
/*  Due to the limted RAM space of mega8. Maximum no repetition    */
/*  songs is 1024. And songs more than that will use randomly play */
/*  Special thanks to Ronald Ausloos (Belgium)'s advice            */ 
/*                                                                 */
/*  V1.5                                                           */
/*  2007-05-03                                                     */
/*  Change the behavior of the LEDs:                               */
/*                      VS1003 faild: LED1 blink                   */
/*                      SD faild    : LED2 blink                   */
/*                      FAT faild   : LED1 & LED2 blink alternatly */
/*                      File not found: Both LED blink             */
/*  Add read capacity function, fix the bug of FAT init            */
/*  Add slow start up code of VS1003                               */ 
/*                                                                 */                                                              
/*  V1.4                                                           */
/*  2007-05-02                                                     */
/*  Add enough delay when operate VS1003                           */ 
/*                                                                 */                                                              
/*  V1.3                                                           */
/*  2007-04-21                                                     */
/*  Modify the retry time of sd reset                              */
/*  Enable some code incase that when FAT initialize               */
/*  faild program can't jump out the loop                          */
/*  so the error LED can't light up                                */
/*  And light up both leds when FAT_Ini fails                      */
/*                                                                 */
/*  V1.2:                                                          */
/*  2007-04-04:                                                    */
/*  Add a macro of path                                            */
/*                                                                 */
/*  V1.1:                                                          */
/*  2007-02-25                                                     */
/*  Change the directory to C:\music\                              */
/*  A bug fixed                                                    */
/*  Modify some code to adjust new GCC compiler                    */
/*                                                                 */
/*  V1.0:                                                          */
/*  2006-12-03:                                                    */
/*  Original Version                                               */
/*******************************************************************/
// F_CPU tells util/delay.h our clock frequency
       #define F_CPU 8000000UL   // Orangutan frequency (8MHz)

#include<avr/io.h>
#include"MMC_SD/MMC_SD.h" //head files
#include"FAT/FAT.h"
#include"VS1003B/VS1003B.h"
#include<avr/pgmspace.h>
#include <avr/interrupt.h>
#include <util/delay.h>

	  const unsigned char single_zero_wheel[37]={0,32,15,19,4,21,2,25,17,34,6,
                                 27,13,36,11,30,8,23,10,5,24,
                                 16,33,1,20,14,31,9,22,18,29,
                                 7,28,12,35,3,26};

const unsigned char single_zero_order[37]={0,23,6,35,4,19,10,31,16,27,18,
                        14,33,12,25,2,21,8,29,3,24,5,
                        28,17,20,7,36,11,32,30,15,26,
                        1,22,9,34,13};

#define uint8 unsigned char
#define uint16 unsigned int
#define uint32 unsigned long


#define PATH (unsigned char *)("\\music")
//It's the path where the file placed
//Change it if you want to placed it to anoter foler
//The path should not have blanks, and each foler name's length should less than 8 with no extention

//diagnose and state indicate leds
//at start up this two led indicate error
//at normal they indicate the state of the MODE 
#define LED1_CON() DDRC|=_BV(PC5)
#define LED1_ON()  PORTC|=_BV(PC5)
#define LED1_OFF() PORTC&=~_BV(PC5)

#define LED2_CON() DDRB|=_BV(PB1)
#define LED2_ON()  PORTB|=_BV(PB1)
#define LED2_OFF() PORTB&=~_BV(PB1)

//keys
#define STOP _BV(PD2)
#define MODE _BV(PD3)
#define NEXT _BV(PD7)
#define UP   _BV(PD4)
#define DOWN _BV(PD6)
#define PREV _BV(PD5)

#define MP3 1
#define WMA 2
#define MID 3

//mode
#define REPET_ALL 0
#define REPET_ONE 1
#define RANDOM    2

extern uint16 SectorsPerClust;
extern uint16 FirstDataSector;   //struct of file information
extern uint8  FAT32_Enable;

struct FileInfoStruct FileInfo;

struct direntry MusicInfo;			//the mp3 file item whichi will be played
uint16 totalsongs;						//total songs in the root directery on the SD card
uint8 type;									//file type

uint8 track[128];			//stroe the information of songs (bit set indicate songs has been played)

void ClearTrackInfo()		//cleare the array track[128]
{
	uint8 i;
	for(i=0;i<128;i++)track[i] = 0;
}

uint8 SetTrack(uint16 songs)//set the track bit, return 1 means the song has been played
{
	uint8 byte_offset;
	uint8 bit_offset;
	songs--;
	byte_offset = songs/8;
	bit_offset = songs%8;
	if(track[byte_offset] & (1<<bit_offset))return 1;
	else
	{
		track[byte_offset] |= 1<<bit_offset;
		return 0;
	}
}

void Delay(uint16 n)//ÑÓʱ
{
	while(n--)asm("nop");
}

//Timer initialization offer seed of the srandom()
void Timer1_Initial()
{
 TCNT1H=0x00;
 TCNT1L=0x00;
 TCCR1B=0x01;//system clock;
 ICR1H=0xff;
 ICR1L=0xff;
}


void PlaySong(uint16 songs){
   uint16 keylen;         //ÓÃÓÚ¼ü´¦Àí      //for key processing
   uint16 count;         //Êý¾Ý¼ÆÊý         //data counting
   uint8 i;            //Ñ­»·±äÁ¿         //loop variable
   uint16 j;            //Ñ­»·±äÁ¿         //loop variable
   uint32 p;            //´Øָʾֵ         //cluster
   uint32 totalsect;      //ÎļþÓµÓеÄÉÈÇøÊý   //cotain the total sector number of a file
   uint16 leftbytes;      //Ê£Óà×Ö½Ú         //cotain the left bytes number of a file //the last cluster usually not fully occupied by the file
   uint8 *buffer;         //»º³å            //buffer
   uint32 sector;         //ÉÈÇø            //recor the current sector to judge the end sector
   uint8 flag;            //²¥·Å/ÔÝÍ£±êÖ¾      //flag of pause
//   uint16 vol=DefaultVolume;//³õʼÒôÁ¿£¬Ó¦Óëvs1003º¯ÊýÀïµÄ³õʼÒôÁ¿Ïàͬ   //default volume
   uint8 mode=DEFAULT_MODE;//µ¥ÇúÖظ´         //repet all by default
   uint16 songs_cnt = 0;               //how many songs have been played
   if(totalsongs==0)return;//Èç¹ûûÓиèÇúÔòÒì³£Í˳ö   //if no music file return
   uint32 rand_val;
   Timer1_Initial();//Æô¶¯¶¨Ê±Æ÷£¬ÓÃÓÚ²úÉúËæ»úº¯ÊýµÄÖÖ×Ó   //initialize the timer
   ClearTrackInfo();
//next://ÏÂÒ»Ê׸èµÄÆðʼµØ·½                  //label for "goto"
   if(mode==RANDOM)//Ëæ»ú²¥·Å¸èÇú             //if the mode is shuffle the songs
   {
      songs_cnt++;
      if(songs_cnt == totalsongs && totalsongs<1025)
      {
         ClearTrackInfo();
         songs_cnt = 0;
      }
      rand_val = TCNT1;
      Delay((random() && 0x00ff));
      rand_val <<= 16;
      rand_val += TCNT1;
      srandom(rand_val);
      if(totalsongs>1024)
      {
         songs = (uint16)(((random()/214749)*(uint32)totalsongs)/10000)+1;//Ëæ»ú²úÉú¸èÇúÐòºÅ   //create random song number
      }
      while(totalsongs<1025)
      {
         songs = (uint16)(((random()/214749)*(uint32)totalsongs)/10000)+1;//Ëæ»ú²úÉú¸èÇúÐòºÅ   //create random song number
         if(SetTrack(songs) == 0)break;
      }   
   }
   count=0;//Çå»ùÊý   //clear count
   flag=1;
   while(count<2048 && (type != MID))//recommand 2048 zeros honoring DREQ befor soft reset
   {                           //ÓÃÓÚ´ÓwmaÌø³öµ½ÏÂÒ»Ê׸裬ºÍÒ»Ê׸è½áÊøÌî³äÊý¾Ý//midi¸ñʽ²»ÐèÒª
      if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0)
      {
         for(j=0;j<32;j++)
         {
            VS1003B_WriteDAT(0x00);//Ìî³ä0   //fill 0
            count++;
         }
         if(count == 2047)break;
      }
   }
   VS1003B_SoftReset();//soft reset //in case of playing wma files//Èí¼þ¸´Î»
   Search(PATH,&MusicInfo,&songs,&type);      //ÕÒµ½ÏàÓ¦µÄÎļþ      //find the file
   p     = MusicInfo.deStartCluster+(((uint32)MusicInfo.deHighClust)<<16);//¶ÁÎļþÊ×´Ø   //the first cluster of the file
      
   totalsect = MusicInfo.deFileSize/512; //¼ÆËãÉÈÇøÊý         //calculate the total sectors
   leftbytes = MusicInfo.deFileSize%512; //¼ÆËãÊ£ÓàµÄ×Ö½ÚÊý   //calculate the left bytes   
   i=0;
   sector=0;
   
   while(1)
   {
      keylen=0;
       for(;i<SectorsPerClust;i++)      //Ò»¸ö´Ø   //a cluster
      {
         buffer=malloc(512);
         FAT_LoadPartCluster(p,i,buffer);//¶ÁÒ»¸öÉÈÇø   //read a sector
         count=0;
         while(count<512)
         {
            if(flag==0){if(keylen){Delay(100);keylen--;}}
            else if(type == MID){if(keylen){Delay(100);keylen--;}}
            if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 && flag)   //¸ù¾ÝÐèÒªËÍÊý¾Ý  //send data  honoring DREQ
            {
               for(j=0;j<32;j++)         //ÿ´ÎËÍ32¸öÊý¾Ý      //32 Bytes each time
               {
                  VS1003B_WriteDAT(buffer[count]);
                  count++;
               }
               if(keylen)keylen--;         //ÓÃÓÚ¼ü´¦Àí         //for key processing
               if(sector == totalsect && count >= leftbytes)      //Èç¹ûÎļþÒѽáÊø      //if this is the end of the file
               {
                  if(type == MID)//waiting the midi file was decoded
                  {//¶ÔÓÚmidÒôÀÖÒª½Ó×ÅËÍ2048¸öÁã
                     count=0;
                     while(count<2048)//recommand 2048 zeros honoring DREQ goto next songs
                     {
                        if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 )
                        {
                           for(j=0;j<32;j++)
                           {
                              VS1003B_WriteDAT(0x00);
                              count++;
                           }
                           if(count == 2047)break;
                        }
                     }
                  }
                  i=SectorsPerClust;
                  break;
               }//Îļþ½áÊø         //file ended
               if(count == 511){break;}//512×Ö½ÚËÍÍêÌø³ö      //break if a sector was sent
            }
            if((PIND&STOP)==0 /*&& keylen==0*/)//²¥·ÅÔÝÍ£¼ü      //key PLAY/PAUSE
             {
                 Delay(100);
               if(!(PIND&STOP))
               {
                  while(!(PIND&STOP));
                   if(flag)flag=0;
                   else flag=1;
                   Delay(1000);
                }
             }
          
             
             
             
         }
         sector++;
         free(buffer);
      }
   }
}






void PlayMusic()//²¥·ÅÒôÀÖº¯Êý£¬Ò»µ©Ö´Ðв»»áÍ˳ö
{
	uint16 keylen;			//ÓÃÓÚ¼ü´¦Àí		//for key processing
	uint16 count;			//Êý¾Ý¼ÆÊý			//data counting
	uint8 i;				//Ñ­»·±äÁ¿			//loop variable
	uint16 j;				//Ñ­»·±äÁ¿			//loop variable
	uint32 p;				//´Øָʾֵ			//cluster
	uint32 totalsect;		//ÎļþÓµÓеÄÉÈÇøÊý	//cotain the total sector number of a file
	uint16 leftbytes;		//Ê£Óà×Ö½Ú			//cotain the left bytes number of a file //the last cluster usually not fully occupied by the file
	uint8 *buffer;			//»º³å				//buffer
	uint32 sector;			//ÉÈÇø				//recor the current sector to judge the end sector
	uint8 flag;				//²¥·Å/ÔÝÍ£±êÖ¾		//flag of pause
//	uint16 vol=DefaultVolume;//³õʼÒôÁ¿£¬Ó¦Óëvs1003º¯ÊýÀïµÄ³õʼÒôÁ¿Ïàͬ	//default volume
	uint16 songs=1;			//ĬÈϷŵÚÒ»Ê׸è	//play the fist songs by default
	uint8 mode=DEFAULT_MODE;//µ¥ÇúÖظ´			//repet all by default
	uint16 songs_cnt = 0;					//how many songs have been played
	if(totalsongs==0)return;//Èç¹ûûÓиèÇúÔòÒì³£Í˳ö	//if no music file return
	uint32 rand_val;
	Timer1_Initial();//Æô¶¯¶¨Ê±Æ÷£¬ÓÃÓÚ²úÉúËæ»úº¯ÊýµÄÖÖ×Ó	//initialize the timer
	ClearTrackInfo();
next://ÏÂÒ»Ê׸èµÄÆðʼµØ·½						//label for "goto"
	if(mode==RANDOM)//Ëæ»ú²¥·Å¸èÇú 				//if the mode is shuffle the songs
	{
		songs_cnt++;
		if(songs_cnt == totalsongs && totalsongs<1025)
		{
			ClearTrackInfo();
			songs_cnt = 0;
		}
		rand_val = TCNT1;
		Delay((random() && 0x00ff));
		rand_val <<= 16;
		rand_val += TCNT1;
		srandom(rand_val);
		if(totalsongs>1024)
		{
			songs = (uint16)(((random()/214749)*(uint32)totalsongs)/10000)+1;//Ëæ»ú²úÉú¸èÇúÐòºÅ	//create random song number
		}
		while(totalsongs<1025)
		{
			songs = (uint16)(((random()/214749)*(uint32)totalsongs)/10000)+1;//Ëæ»ú²úÉú¸èÇúÐòºÅ	//create random song number
			if(SetTrack(songs) == 0)break;
		}	
	}
	count=0;//Çå»ùÊý	//clear count
	flag=1;
	while(count<2048 && (type != MID))//recommand 2048 zeros honoring DREQ befor soft reset
	{									//ÓÃÓÚ´ÓwmaÌø³öµ½ÏÂÒ»Ê׸裬ºÍÒ»Ê׸è½áÊøÌî³äÊý¾Ý//midi¸ñʽ²»ÐèÒª
		if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0)
		{
			for(j=0;j<32;j++)
			{
				VS1003B_WriteDAT(0x00);//Ìî³ä0	//fill 0
				count++;
			}
			if(count == 2047)break;
		}
	}
	VS1003B_SoftReset();//soft reset //in case of playing wma files//Èí¼þ¸´Î»
	Search(PATH,&MusicInfo,&songs,&type);		//ÕÒµ½ÏàÓ¦µÄÎļþ		//find the file
	p     = MusicInfo.deStartCluster+(((uint32)MusicInfo.deHighClust)<<16);//¶ÁÎļþÊ×´Ø	//the first cluster of the file
		
	totalsect = MusicInfo.deFileSize/512; //¼ÆËãÉÈÇøÊý			//calculate the total sectors
	leftbytes = MusicInfo.deFileSize%512; //¼ÆËãÊ£ÓàµÄ×Ö½ÚÊý	//calculate the left bytes	
	i=0;
	sector=0;
	
	while(1)
	{
		keylen=0;
    	for(;i<SectorsPerClust;i++)		//Ò»¸ö´Ø	//a cluster
		{
			buffer=malloc(512);
			FAT_LoadPartCluster(p,i,buffer);//¶ÁÒ»¸öÉÈÇø	//read a sector
			count=0;
			while(count<512)
			{
				if(flag==0){if(keylen){Delay(100);keylen--;}}
				else if(type == MID){if(keylen){Delay(100);keylen--;}}
				if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 && flag)	//¸ù¾ÝÐèÒªËÍÊý¾Ý  //send data  honoring DREQ
				{
					for(j=0;j<32;j++)			//ÿ´ÎËÍ32¸öÊý¾Ý		//32 Bytes each time
					{
						VS1003B_WriteDAT(buffer[count]);
						count++;
					}
					if(keylen)keylen--;			//ÓÃÓÚ¼ü´¦Àí			//for key processing
					if(sector == totalsect && count >= leftbytes)		//Èç¹ûÎļþÒѽáÊø		//if this is the end of the file
					{
						if(type == MID)//waiting the midi file was decoded
						{//¶ÔÓÚmidÒôÀÖÒª½Ó×ÅËÍ2048¸öÁã
							count=0;
							while(count<2048)//recommand 2048 zeros honoring DREQ goto next songs
							{
								if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 )
								{
									for(j=0;j<32;j++)
									{
										VS1003B_WriteDAT(0x00);
										count++;
									}
									if(count == 2047)break;
								}
							}
						}
						i=SectorsPerClust;
						break;
					}//Îļþ½áÊø			//file ended
					if(count == 511){break;}//512×Ö½ÚËÍÍêÌø³ö		//break if a sector was sent
				}
				if((PIND&STOP)==0 /*&& keylen==0*/)//²¥·ÅÔÝÍ£¼ü		//key PLAY/PAUSE
			    {
	 			    Delay(100);
					if(!(PIND&STOP))
					{
						while(!(PIND&STOP));
						 if(flag)flag=0;
						 else flag=1;
						 Delay(1000);
					 }
				 }
				
				 else if((!(PIND&MODE)) && keylen==0) //ģʽ			//mode key
	 			 {
					Delay(100);		
					if(!(PIND&MODE))
					{
						keylen=0xffff;
						if(mode==REPET_ALL)
						{
							mode=REPET_ONE;
							LED1_ON();
							LED2_OFF();
						}
						else if(mode==REPET_ONE)//next mode is shuffle
						{
							mode=RANDOM;
							LED1_OFF();
							LED2_ON();
							srandom(((uint32)TCNT1)<<16);//²úÉúËæ»úÊýµÄÖÖ×Ó
						}
						else 
						{
							mode=REPET_ALL;
							LED1_OFF();
							LED2_OFF();
						}
					}
	  			 }
			}
			sector++;
			free(buffer);
		}
		i=0;
		p=FAT_NextCluster(p);//¶ÁÏÂÒ»´ØÊý¾Ý			//read next cluster
		if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p == 0xffff))//Èç¹ûÎÞºóÐø´ØÔò½áÊø£¬	//no more cluster
		{
				if(mode==REPET_ALL)songs++;
				if(songs>totalsongs)songs=1;
				goto next;
				main();
		}
	}
}






//-----------------------------------------
        //All to do with ADC......................
        //-----------------------------------------
void analog_init(void)
{

ADMUX = (1 << REFS0);

ADCSRA = (6 << ADPS0);


ADCSRA |= (1 << ADEN);
}

unsigned int analog10(unsigned char channel)
{

ADMUX &= ~0x1F;

ADMUX |= channel;

ADCSRA |= (1 << ADSC);

while (bit_is_set(ADCSRA, ADSC));


return (ADCL | ADCH << 4); // read ADC (full 10 bits);
}

unsigned int analog8(unsigned char channel)
{
return(analog10(channel) >> 2);
}
		//-----------------------------------------
        //Finish - All to do with ADC......................
        //-----------------------------------------

      	unsigned int time_ms1 = 0;
   		unsigned int time_ms2 = 0;
		unsigned int wheel_ms1 = 0;
		unsigned int wheel_ms2 = 0;
     	volatile unsigned int timer_tick;      		//global timer variable MUST BE DECLARED VOLATILE
		volatile unsigned int timer_tick_wheel;     //global timer variable MUST BE DECLARED VOLATILE
        

//-----------------------------------
//Functions detmining ball position
//-----------------------------------

int time(){
   time_ms1 = 0; 
   time_ms2 = 0;

   
    while (PIND&(1<<PD6));  // loop here until first button press
    TCNT0 = 0;
    timer_tick=0;// here is where we start timing
    _delay_ms(1);  // delay for 1 ms to debounce button press

    while (!(PIND&(1<<PD6)));  // loop here until button is released
    _delay_ms(10);  // delay for 10 ms to debounce button release
   
   
    while (PIND&(1<<PD6));  // loop here until second button press
    time_ms1 = timer_tick;      //get the value of the millisecond counter
     timer_tick=0;// here is where reset the timer
    _delay_ms(1);  // delay for 1 ms to debounce button press
       
    while (!(PIND&(1<<PD6)));  // loop here until button is released
   
    _delay_ms(10);  // delay for 10 ms to debounce button release
   
    while (PIND&(1<<PD6));  // loop here until 3rd button press
    time_ms2 = timer_tick;      //get the value of the millisecond counter
   
//    lcd_line1();// display the times
//    lcd_time(time_ms1);
//    lcd_line2();
//    lcd_time(time_ms2);

 _delay_ms(1000);  // delay for 10 ms to debounce button release
//  lcd_clear();
  main();
return(0);
}

int wheel(void){
   wheel_ms1 = 0; 
   wheel_ms1 = 0;

   
    while (PIND&(1<<PD7));  // loop here until first button press
    TCNT0 = 0;
    timer_tick_wheel=0;// here is where we start timing
    _delay_ms(1);  // delay for 1 ms to debounce button press

    while (!(PIND&(1<<PD7)));  // loop here until button is released
    _delay_ms(10);  // delay for 10 ms to debounce button release
   
   
    while (PIND&(1<<PD7));  // loop here until second button press
    wheel_ms1 = timer_tick_wheel;      //get the value of the millisecond counter
     timer_tick_wheel=0;// here is where reset the timer
    _delay_ms(1);  // delay for 1 ms to debounce button press
       
    while (!(PIND&(1<<PD7)));  // loop here until button is released
   
    _delay_ms(10);  // delay for 10 ms to debounce button release
   
    while (PIND&(1<<PD7));  // loop here until 3rd button press
    wheel_ms2 = timer_tick_wheel;      //get the value of the millisecond counter
   
//    lcd_line1();// display the times
  //  lcd_time(wheel_ms1);
    //lcd_line2();
    //lcd_time(wheel_ms2);
PlaySong(wheel_ms2);
 _delay_ms(1000);  
   //lcd_clear();
	main();
return(0);
}
unsigned char pot_idx=0;
int roulette_pot()
{
PORTD|=(1<<PD5);
unsigned char i;
while(1)
      {


// Initialize the ADC:
      analog_init();


// The endless loop
 while(PIND&(1<<PD5)){//while button PD5 is not pressed
     // scale the potentiometer ADC value (0 - 255) to be a number from 0 - 36
     pot_idx=(unsigned char)(analog8(4)*36/255);

     //lcd_line2();
     //lcd_int(pot_idx);
     
     _delay_ms(25);
   }
   
   pot_idx=single_zero_order[pot_idx];
   
   while(pot_idx<=37){
     //lcd_line1();
     //lcd_int(single_zero_wheel[pot_idx]);
     PlaySong(single_zero_wheel[pot_idx]);	//play songs
     pot_idx++;//increment pot_idx
     
     for(i=0;i<10;i++){
       _delay_ms(100);
     }
	 

}  
_delay_ms(1000);  
//   lcd_clear();
	
}
return(0);
}

/*int equation()
{
unsigned char i, p;
for (p=0; p<8;p++){
    // lcd_line1();
     //lcd_int(single_zero_wheel[pot_idx]);
     
	PlaySong(single_zero_wheel[pot_idx]);	//play songs
     pot_idx++;//increment pot_idx
     

     for(i=0;i<10;i++){
       _delay_ms(100);	
	  
     }
	 

}
}*/
//-----------------------------------
// End of Functions detmining ball position
//-----------------------------------

//main function
int main()
{
	uint8 retry = 0;

	DDRD &= 0x03;//³õʼ»¯¶Ë¿Ú
	PORTD |= 0xfc;
	
	LED1_CON();
	LED1_OFF();
	LED2_CON();
	LED2_OFF();


	OSCCAL = 0x00;//×îСRCÕñµ´ÆµÂÊ	//in order to operate some low speed card the initialization should run at lowest speed

	Delay(0xffff);

	MMC_SD_Init();//³õʼ»¯spi¿Ú		//SPI initialize

	Delay(0xffff);

	if(VS1003B_Init())
	{
		//LED1_ON();//ÅäÖÃVS1003	//config vs1003
		while(1)
		{
			LED1_ON();
			Delay(0xffff);
			LED1_OFF();
			Delay(0xffff);
		}
	}
	Delay(0xffff);//Ìṩ×ã¹»µÄÑÓʱ				//supply enough delay
	Delay(0xffff);
	Delay(0xffff);
	Delay(0xffff);
	Delay(0xffff);

	while(MMC_SD_Reset())//³õʼ»¯SD¿¨					//sd card initialize
	{
		retry++;
		if(retry>20)
		{
		//	LED2_ON();
			while(1)
			{
				LED2_ON();
				Delay(0xffff);
				LED2_OFF();
				Delay(0xffff);
			}
		}
	}

	OSCCAL = 0xff;//×î´óRCÕñµ´ÆµÂÊ				//normal operation maximum the frequency

	Delay(0xffff);								//wait for stable

	if(FAT_Init())//³õʼ»¯Îļþϵͳ Ö§³ÖFAT16ºÍFAT32	//initialize file system  FAT16 and FAT32 are supported
	{
	//	LED1_ON();
	//	LED2_ON();
	//	while(1);
		while(1)
		{
			LED1_ON();LED2_ON();
			Delay(0xffff);
			LED1_OFF();LED2_OFF();
			Delay(0xffff);
		}

	}
	Search(PATH,&MusicInfo,&totalsongs,&type);
	//search the songs in the root directery on the SD card
	//You can also specify the directery where the songs are placed
	//eg: Search("\\new\\mp3",&MusicInfo,&totalsongs,&type);
	//		means search the file in the foler C:\new\mp3



DDRC &= ~(1 << PD6);
   PORTD|=(1<<PD6); 
   
   DDRC &= ~(1 << PD7);
   PORTD|=(1<<PD7);

   DDRC &= ~(1 << PD5);
   PORTD|=(1<<PD5);
      
   //initialize timer 0
    TCNT0=~(124);//preload counter to overflow after 1 ms (125 counts)
   TIMSK0=(1<<TOIE0);//enable interrupt on timer0 overflow
   TCCR0B=(1<<CS01)|(1<<CS00);//set timer to normal mode with CPU clock/64 (125 kHz)
   
   sei();//enable all interrupts
   
   // time an event:
   timer_tick=0;
   timer_tick_wheel=0;            //start timer, clear global millisecond counter
   TCNT0 = ~(124);
      
   while(1){
      if (!(PIND&(1<<PD7))){
	  LED2_ON();
				Delay(0xffff);
				LED2_OFF();
				Delay(0xffff);
         _delay_ms(10);//delay for 10 ms to debounce the press
         time();
         break;
      }else if(!(PIND&(1<<PD6))){
	  LED2_ON();
				Delay(0xffff);
				LED2_OFF();
				Delay(0xffff);
         _delay_ms(10);//delay for 10 ms to debounce the press
        	roulette_pot();//run a different function
         break;
      }else if(!(PIND&(1<<PD5))){
	  LED2_ON();
				Delay(0xffff);
				LED2_OFF();
				Delay(0xffff);
         _delay_ms(10);//delay for 10 ms to debounce the press
         wheel();//run function to take number ball started on.
         break;
      }else if(!(PIND&(1<<PC2))){
	  LED2_ON();
				Delay(0xffff);
				LED2_OFF();
				Delay(0xffff);
         _delay_ms(10);//delay for 10 ms to debounce the press
         
         break;

}
   }

   

//PlayMusic();	
	while(1)
	{
		while(1)
		{
			LED1_ON();LED2_OFF();
			Delay(0xffff);
			LED2_ON();LED1_OFF();
			Delay(0xffff);
		}
	}
	return 0;
}


/*
TIMER 0 overflow interrupt service routine
This routine is called every millisecond
Operation: increment global variable timer_tick, reload TCNT0 to count 125 clock cycles
*/

ISR(TIMER0_OVF_vect)
{
   timer_tick++;
   timer_tick_wheel++;
   TCNT0 = ~(125);         //preload counter to overflow after 1 ms (125 counts)
}


Its the functions roulette and the initiation of the adc that really matter I think. i saw a line of it in the roulette that might be it, but i changed it ( i thought) and it still didnt work?

Again, since I don’t have your hardware to test on, I can’t say if these fixes will make everything work for you, but they’ll certainly help:

  1. I’m a little confused about where this line in your analog_init() function came from:
    ADMUX = (1 << REFS0);
    The ADC hardware needs a reference voltage to compare your input voltage to. Normally this voltage is supplied on by connecting +5v to the AREF pin, but this line of code switches over to using the AVCC pin as the reference voltage. In this configuration, you’re supposed to put a capacitor between the AREF pin and ground to cancel out noise. The problem in your case is that all of the Orangutans connect the AREF pin to +5V, and:

So, you could wire up your breadboard to work this way, but this code won’t work properly on any Orangutan. You should drop that line from your ‘analog_init()’ function. Actually, you can combine the other two lines like this:

void analog_init(void){
	ADCSRA|=(6<<ADPS0)|(1<<ADEN);
}

Now it should work on your Orangutan, and to make it work on your breadboard just add a connection from the AREF pin (pin 21 on the DIP chip) to +5V.

  1. Move the ‘analog_init()’ function call out of the roulette_pot() to near the top of the main() function. It only needs to be run once, and this way the ADC will be set to go whenever you need it.

  2. Get rid of all instances of your program calling the ‘main()’ function, specifically at the end of PlayMusic(), time(), wheel(), these are nothing but trouble! You call these functions from main(), and they will automatically return to that part of main() when they are done. In general it is never correct for you to call ‘main()’ like a function. It may work a little, but very quickly it leads to problems like one-time code being executed multiple times, and infinite loops within the program that fill up it’s ram with the list of functions that have called each other but have not yet returned.

Think of it this way, lets say you and I have a phones with super-duper call waiting that lets us put up to 100 calls on hold. In a normal day, you only put maybe one, or possibly two calls on hold at a time to talk to other friends, but normally you never even come close to using all of your phone lines. Now what if you call me and ask a question, then I put you on hold, and call you back on a new line to answer. You then put me on hold and call me again on a new line to ask another question. Now I put this call on hold and call you back again to respond. If we keep calling each other back and forth like this pretty soon our call waiting will be full to capacity, and when one of us tries to call the other he’ll get a busy signal (plus we’re racking up some crazy long-distance phone bills!).

This is pretty much what happens when main() (in this case, you) calls a function (in this case, me) which calls it back. Of course, what we should happen when you call me with a question is that I answer right back to you, we say goodbye, and hang up. Then when you have another question you can just call me up again.

I hope this all works now!

-Adan

1 Like

That was very useful, again though i;m at work and cant try it until i get home.

In the main function, the you can see i have se it to flash an led when i press a button. This works the first time. but will it work again once the function go back to main()? I was having trouble with that.

Off the topic, in my list of posted threads in the user area, this MAMMOTH thread has a little picture to the leftlike paper scrolling, and next to that a small orange box with the corner turned over, what do they mean?

I hope all this works, after that i am going to look at writing to SD!

Will that initiate the ADC on pin 27?

Right now the ‘analog_init’ function just sets up the analog to digital converter. You pick which pin it will read from when you call the analog8 function. For example, analog8(4) returns an 8-bit reading from ADC4, which is pin 27 on the DIP package ATMega168.

I think you’re viewing the forum with a different skin that I’m seeing it with right now, but the scrolling paper just means it’s a “hot topic,” or a thread that gets many posts. Orange lines of text mean that there are new posts in a topic that you haven’t read yet, and the little orange box might just mean that this is a thread you’ve posted in (I see red stars over topics I’ve posted in).

-Adam

Thats what I;ve got though. I have it set up how you told me and removed the errors. Then in the roulette_pot function, I initiate the adc 4 in the line:

pot_idx=(unsigned char)(analog8(4)*36/255);

But all it does is tell me the number 7, wherever the sliding pot actually is!

It also doesnt move to the next one. The code is telling it to increase pot_idx by 1 each time and then say the number but it just says “7” and stops…

I took the config of which pins of the sliding pot from the orangutan and how i plug it in there…

Found another odd mistake in your code, your ‘analog10’ function is a little wacky (and the analog8 function relies on the analog10 function).

The line:
return (ADCL | ADCH << 4); // read ADC (full 10 bits);

Should read:
return (ADCL | ADCH << 8); // read ADC (full 10 bits);

Or simply:
return ADC; // read ADC (full 10 bits);

Does that help? With that change, and if I change the code around as little as possible to read ADC7 (the Orangutan’s trim potentiometer) and display to the LCD screen, I see the numbers 0-36 go by like you were trying to achieve.

Without the same hardware I’m having to comment out lots of your code to get it to compile in a way that will run on a stock Orangutan, so I’m probably missing some other problems. I think that mixing these three programs, the mp3 player program, the roulette wheel AND the lap-counting stopwatch, is causing you trouble. I think it would be worth it for you to go back to the original mp3 player code and bring in parts of your roulette program one function at a time.

Good luck!

-Adam

Yeah I changed that, thinking that was where i state which adc pin to read, because I’m still not sure i have the correct one…

I am thinking that if it is not picking up the correct adc then its default might be the index number of the song “7”.

I’ll try removing things, but the two functions that record time, are nothing to do with the adc function, and it does work on the orangutan, with the slide pot.

Is the line where you state which adc pin to read the one in the roulette_pot function, that is /255 and the *36?