void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Wave test!"); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(redled, OUTPUT); if (!card.init_card()) { putstring_nl("Card init. failed!"); return; } if (!card.open_partition()) { putstring_nl("No partition!"); return; } if (!card.open_filesys()) { putstring_nl("Couldn't open filesys"); return; } if (!card.open_rootdir()) { putstring_nl("Couldn't open dir"); return; } putstring_nl("Files found:"); ls(); }
void setup() { Serial.begin(9600); TCCR2A = 0; TCCR2B = 0; digitalWrite(LED, LOW); digitalWrite(IRLED, LOW); pinMode(LED, OUTPUT); pinMode(IRLED, OUTPUT); pinMode(REGIONSWITCH, INPUT); pinMode(TRIGGER, INPUT); digitalWrite(REGIONSWITCH, HIGH); //Pull-up digitalWrite(TRIGGER, HIGH); delay_ten_us(5000); // Let everything settle for a bit // determine region if (digitalRead(REGIONSWITCH)) { region = US; // US DEBUGP(putstring_nl("US")); } else { region = EU; DEBUGP(putstring_nl("EU")); } // Tell the user what region we're in - 3 is US 4 is EU quickflashLEDx(3+region); // Indicate how big our database is DEBUGP(putstring("\n\rNA Codesize: "); putnum_ud(num_NAcodes); );
void playfile(char *name) { f = card.open_file(name); if (!f) { putstring_nl(" Couldn't open file"); return; } if (!wave.create(f)) { putstring_nl(" Not a valid WAV"); return; } // ok time to play! wave.play(); }
//////////////////////////////////// SETUP void setup() { Serial.begin(9600); // set up Serial library at 9600 bps for debugging putstring_nl("\nWave test!"); // say we woke up! putstring("Free RAM: "); // This can help with debugging, running out of RAM is bad Serial.println(FreeRam()); // if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you if (!card.init()) { //play with 8 MHz spi (default faster!) error("Card init. failed!"); // Something went wrong, lets print out why } // enable optimize read - some cards may timeout. Disable if you're having problems card.partialBlockRead(true); // Now we will look for a FAT partition! uint8_t part; for (part = 0; part < 5; part++) { // we have up to 5 slots to look in if (vol.init(card, part)) break; // we found one, lets bail } if (part == 5) { // if we ended up not finding one :( error("No valid FAT partition!"); // Something went wrong, lets print out why } // Lets tell the user about what we found putstring("Using partition "); Serial.print(part, DEC); putstring(", type is FAT"); Serial.println(vol.fatType(), DEC); // FAT16 or FAT32? // Try to open the root directory if (!root.openRoot(vol)) { error("Can't open root dir!"); // Something went wrong, } // Whew! We got past the tough parts. putstring_nl("Files found (* = fragmented):"); // Print out all of the files in all the directories. root.ls(LS_R | LS_FLAG_FRAGMENTED); }
// // Function: spotMenuBarUpdate // // Put a (not so special) header in a Spotfire clock menu bar // static void spotMenuBarUpdate(void) { // Only get a new menu bar when the date has changed or when we're // initializing if (mcClockDateEvent == GLCD_TRUE || mcClockInit == GLCD_TRUE) { uint8_t i = 1; uint8_t posX; menuBarDriver_t *mbDriver = menuBarDriver; // Find the new menu bar while (i < sizeof(menuBarDriver) / sizeof(menuBarDriver_t)) { if (mcClockNewDD == mbDriver->day && mcClockNewDM == mbDriver->month) break; i++; mbDriver++; } // Only update the menu bar if it has changed if (menuBarId != i) { DEBUG(putstring("Menu bar Id -> ")); DEBUG(uart_putw_dec(i)); DEBUG(putstring_nl("")); // Sync new menu bar menuBarId = i; // Get starting position on x axis if (mbDriver->barText == MBAR_TXT_LEFT) { // Text is to be started at left (with a small align indent) posX = 2; } else { // Text is to be centered posX = glcdGetWidthStr(FONT_5X5P, mbDriver->msg1); if (mbDriver->msg2 != 0) posX = posX + glcdGetWidthStr(FONT_5X5P, mbDriver->msg2); posX = (GLCD_XPIXELS - posX + 1) / 2; } // Clear the current bar glcdFillRectangle(0, 0, GLCD_XPIXELS, 7, mcBgColor); // Print the first and optionally second msg string posX = posX + glcdPutStr2(posX, 1, FONT_5X5P, mbDriver->msg1, mcFgColor); if (mbDriver->msg2 != 0) glcdPutStr2(posX, 1, FONT_5X5P, mbDriver->msg2, mcFgColor); } } }
void ls() { char name[13]; int ret; card.reset_dir(); putstring_nl("Files found:"); while (1) { ret = card.get_next_name_in_dir(name); if (!ret) { card.reset_dir(); return; } Serial.println(name); } }
/** * Read a wave file's metadata and initialize member variables. * * \param[in] f A open FatReader instance for the wave file. * * \return The value one, true, is returned for success and * the value zero, false, is returned for failure. Reasons * for failure include I/O error, an invalid wave file or a wave * file with features that WaveHC does not support. */ uint8_t WaveHC::create(FatReader &f) { // 18 byte buffer // can use this since Arduino and RIFF are Little Endian union { struct { char id[4]; uint32_t size; char data[4]; } riff; // riff chunk struct { uint16_t compress; uint16_t channels; uint32_t sampleRate; uint32_t bytesPerSecond; uint16_t blockAlign; uint16_t bitsPerSample; uint16_t extraBytes; } fmt; // fmt data } buf; #if OPTIMIZE_CONTIGUOUS // set optimized read for contiguous files f.optimizeContiguous(); #endif // OPTIMIZE_CONTIGUOUS // must start with WAVE header if (f.read(&buf, 12) != 12 || strncmp(buf.riff.id, "RIFF", 4) || strncmp(buf.riff.data, "WAVE", 4)) { return false; } // next chunk must be fmt if (f.read(&buf, 8) != 8 || strncmp(buf.riff.id, "fmt ", 4)) { return false; } // fmt chunk size must be 16 or 18 uint16_t size = buf.riff.size; if (size == 16 || size == 18) { if (f.read(&buf, size) != (int16_t)size) { return false; } } else { // compressed data - force error buf.fmt.compress = 0; } if (buf.fmt.compress != 1 || (size == 18 && buf.fmt.extraBytes != 0)) { putstring_nl("Compression not supported"); return false; } Channels = buf.fmt.channels; if (Channels > 2) { putstring_nl("Not mono/stereo!"); return false; } else if (Channels > 1) { putstring_nl(" Warning stereo file!"); } BitsPerSample = buf.fmt.bitsPerSample; if (BitsPerSample > 16) { putstring_nl("More than 16 bits per sample!"); return false; } dwSamplesPerSec = buf.fmt.sampleRate; uint32_t clockRate = dwSamplesPerSec*Channels; uint32_t byteRate = clockRate*BitsPerSample/8; #if RATE_ERROR_LEVEL > 0 if (clockRate > MAX_CLOCK_RATE || byteRate > MAX_BYTE_RATE) { putstring_nl("Sample rate too high!"); if (RATE_ERROR_LEVEL > 1) { return false; } } else if (byteRate > 44100 && !f.isContiguous()) { putstring_nl("High rate fragmented file!"); if (RATE_ERROR_LEVEL > 1) { return false; } } #endif // RATE_ERROR_LEVEL > 0 fd = &f; errors = 0; isplaying = 0; remainingBytesInChunk = 0; #if DVOLUME volume = 0; #endif //DVOLUME // position to data return readWaveData(0, 0) < 0 ? false: true; }
void step_rat(void) { // The keepout is used to know where to -not- put the paddle // the 'bouncepos' is where we expect the ball's y-coord to be when // it intersects with the paddle area static uint8_t right_keepout_top, right_keepout_bot; static uint8_t left_keepout_top, left_keepout_bot; static uint16_t dest_paddle_pos; static uint16_t right_dest, left_dest; // Save old ball location so we can do some vector stuff oldball_x = ball_x; oldball_y = ball_y; // move ball according to the vector ball_x += ball_dx; ball_y += ball_dy; /************************************* TOP & BOTTOM WALLS */ // bouncing off bottom wall, reverse direction // if (ball_y > (SCREEN_H_FIXED - BALL_RADIUS*2*FIXED_MATH - BOTBAR_H_FIXED)) { if (ball_y > (SCREEN_H - BOTBAR_H - BALL_RADIUS*2)*FIXED_MATH) { //DEBUG(putstring_nl("bottom wall bounce")); ball_y = (SCREEN_H - BOTBAR_H - BALL_RADIUS*2)*FIXED_MATH; ball_dy = -ball_dy; } // bouncing off top wall, reverse direction if (ball_y < TOPBAR_H_FIXED) { //DEBUG(putstring_nl("top wall bounce")); ball_y = TOPBAR_H_FIXED; ball_dy = -ball_dy; } /************************************* LEFT & RIGHT WALLS */ // the ball hits either wall, the ball resets location & angle if ( ((INT_MSB(ball_x)) > (SCREEN_W - BALL_RADIUS*2)) || ((int8_t)(INT_MSB(ball_x)) <= 0) || ((ball_dx ==0) && (ball_dy==0)) ) { if(DEBUGGING) { if ((int8_t)(INT_MSB(ball_x)) <= 0) { putstring("Left wall collide"); if (! minute_changed) { putstring_nl("...on accident"); } else { putstring_nl("...on purpose"); } } else { putstring("Right wall collide"); if (! hour_changed) { putstring_nl("...on accident"); } else { putstring_nl("...on purpose"); } } } // place ball in the middle of the screen ball_x = (SCREEN_W/2 - BALL_RADIUS)*FIXED_MATH; ball_y = (SCREEN_H/2 - BALL_RADIUS)*FIXED_MATH; // TODO JMM: don't use cosine/sine... pick one randomly and calc the other one. int8_t angle = random_angle(); ball_dx = (int16_t) (((int32_t) MAX_BALL_SPEED * cosine(angle)) / 0x7FFF); ball_dy = (int16_t) (((int32_t) MAX_BALL_SPEED * sine(angle)) / 0x7FFF); glcdFillRectangle(LEFTPADDLE_X, left_keepout_top, PADDLE_W, left_keepout_bot - left_keepout_top, 0); glcdFillRectangle(RIGHTPADDLE_X, right_keepout_top, PADDLE_W, right_keepout_bot - right_keepout_top, 0); right_keepout_top = right_keepout_bot = 0; left_keepout_top = left_keepout_bot = 0; redraw_time_rat = 1; minute_changed = hour_changed = 0; ticksremaining = calculate_dest_pos(&left_dest, &right_dest, &dest_paddle_pos, ball_dx > 0); //left_score = time_h; //right_score = time_m; setscore_rat(); } // save old paddle position oldleftpaddle_y = leftpaddle_y; oldrightpaddle_y = rightpaddle_y; /* if(ball_dx > 0) { // For debugging, print the ball location DEBUG(putstring("ball @ (")); DEBUG(uart_putw_dec(ball_x)); DEBUG(putstring(", ")); DEBUG(uart_putw_dec(ball_y)); DEBUG(putstring(")")); DEBUG(putstring(" ball_dx @ (")); DEBUG(uart_putw_dec(ball_dx)); DEBUG(putstring(")")); DEBUG(putstring(" ball_dy @ (")); DEBUG(uart_putw_dec(ball_dy)); DEBUG(putstring(")")); DEBUG(putstring(" ball_dy @ (")); DEBUG(uart_putw_dec(ball_dy)); DEBUG(putstring(")")); }*/ /*if(!minute_changed) { if((ball_dx < 0) && (ball_x < (SCREEN_W/2)*FIXED_MATH)) { move_paddle(&leftpaddle_y, ball_y); } } else { //Minute changed. We now have to miss the ball on purpose, if at all possible. //If we don't succeed this time around, we will try again next time around. if((ball_dx < 0) && (ball_x < (SCREEN_W/2)*FIXED_MATH) ) { move_paddle(&leftpaddle_y, dest_paddle_pos); } }*/ //ticksremaining--; if((ball_dx < 0) && (ball_x < (SCREEN_W/2)*FIXED_MATH) ) { move_paddle(&leftpaddle_y, minute_changed?dest_paddle_pos:(ball_y-(PADDLE_H_FIXED/3))); } else if((ball_dx > 0) && (ball_x > (SCREEN_W/2)*FIXED_MATH) ) { move_paddle(&rightpaddle_y, hour_changed?dest_paddle_pos:(ball_y-(PADDLE_H_FIXED/3))); } else { if(ball_dx < 0) ticksremaining = calculate_dest_pos(&left_dest, &right_dest, &dest_paddle_pos, 1); else ticksremaining = calculate_dest_pos(&left_dest, &right_dest, &dest_paddle_pos, 0); } // make sure the paddles dont hit the top or bottom if (leftpaddle_y < TOPBAR_H_FIXED +1) leftpaddle_y = TOPBAR_H_FIXED + 1; if (rightpaddle_y < TOPBAR_H_FIXED + 1) rightpaddle_y = TOPBAR_H_FIXED + 1; if (leftpaddle_y > ((SCREEN_H - PADDLE_H - BOTBAR_H)*FIXED_MATH - 1)) leftpaddle_y = ((SCREEN_H - PADDLE_H - BOTBAR_H)*FIXED_MATH - 1); if (rightpaddle_y> ((SCREEN_H - PADDLE_H - BOTBAR_H)*FIXED_MATH - 1)) rightpaddle_y = ((SCREEN_H - PADDLE_H - BOTBAR_H)*FIXED_MATH - 1); if ((ball_dx > 0) && intersectrect(INT_MSB(ball_x), INT_MSB(ball_y), BALL_RADIUS*2, BALL_RADIUS*2, RIGHTPADDLE_X, INT_MSB(rightpaddle_y), PADDLE_W, PADDLE_H)) { ball_dx = -ball_dx; ball_x = RIGHTPADDLE_X_FIXED - (BALL_RADIUS*2*FIXED_MATH); //ball_y = right_dest; //ticksremaining = calculate_dest_pos(&left_dest, &right_dest, &dest_paddle_pos, 1); } if ((ball_dx < 0) && intersectrect(INT_MSB(ball_x), INT_MSB(ball_y), BALL_RADIUS*2, BALL_RADIUS*2, LEFTPADDLE_X, INT_MSB(leftpaddle_y), PADDLE_W, PADDLE_H)) { ball_dx = -ball_dx; ball_x = LEFTPADDLE_X_FIXED + PADDLE_W_FIXED; //ball_y = left_dest; //ticksremaining = calculate_dest_pos(&left_dest, &right_dest, &dest_paddle_pos, 0); } }
void setscore_rat(void) { if(score_mode != last_score_mode_rat) { redraw_time_rat = 1; last_score_mode_rat = score_mode; } switch(score_mode) { #ifdef OPTION_DOW_DATELONG case SCORE_MODE_DOW: break; case SCORE_MODE_DATELONG: right_score = date_d; break; #endif case SCORE_MODE_TIME: if((minute_changed || hour_changed)) { if(hour_changed) { left_score = hours(old_h); right_score = old_m; } else if (minute_changed) { right_score = old_m; } } else { left_score = hours(time_h); right_score = time_m; } break; case SCORE_MODE_DATE: #ifdef OPTION_DOW_DATELONG if((region == REGION_US)||(region == DOW_REGION_US)) { #else if(region == REGION_US) { #endif left_score = date_m; right_score = date_d; } else { left_score = date_d; right_score = date_m; } break; case SCORE_MODE_YEAR: left_score = 20; right_score = date_y; break; case SCORE_MODE_ALARM: left_score = hours(alarm_h); right_score = alarm_m; break; } } int16_t ticksremaining; //JMM !! FIX THIS !! It's a global and it's passed as an arg void initanim_rat(void) { DEBUG(putstring("screen width: ")); DEBUG(uart_putw_dec(GLCD_XPIXELS)); DEBUG(putstring("\n\rscreen height: ")); DEBUG(uart_putw_dec(GLCD_YPIXELS)); DEBUG(putstring_nl("")); oldball_x = ball_x = 25*FIXED_MATH; oldball_y = ball_y = 25*FIXED_MATH; //Somewhere away from 0,0. oldleftpaddle_y = leftpaddle_y = 25*FIXED_MATH; oldrightpaddle_y = rightpaddle_y = 25*FIXED_MATH; init_crand(); ball_dx = ball_dy = 0; initdisplay_rat(0); }
void setup(void) { //Serial.begin(9600); // uart_init(BRRL_192); //// turn on backlight //BLA_DDR |= _BV(BLA); //BLA_PORT |= _BV(BLA); LED_DDR |= _BV(LED); // Serial.println("init"); putstring_nl("init!"); st7565_init(); /* while (1) { spiwrite(0x55); _delay_ms(100); } */ //Serial.println("on"); putstring_nl("on"); st7565_command(CMD_DISPLAY_ON); //Serial.println("normal"); putstring_nl("normal"); st7565_command(CMD_SET_ALLPTS_NORMAL); //Serial.println("bright"); putstring_nl("bright"); st7565_set_brightness(0x18); //Serial.println("clear"); putstring_nl("clear"); clear_screen(); //Serial.println("blit"); putstring_nl("blit"); write_buffer(buffer); //putstring_nl("done"); //_delay_ms(250); //clear_buffer(buffer); //uint8_t i, j = 0; //for(j=0; j<32; j+=8){ // for(i=0; i<128; i++){ // setpixel(buffer, i, j, 1) ; // } // } //write_buffer(buffer); //LED_PORT |= _BV(LED); //drawrect(buffer, 10, 10, 2, 2, 1); // testdrawrect(buffer); // testfillrect(buffer); // testdrawline(buffer); //testdrawcircle(buffer); //fillcircle(buffer, 32, 32, 10, 1); //testdrawchar(buffer); // drawstring(buffer, 0, 0, "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."); ////testdrawbitmap(buffer, logo_glcd_bmp, 16, 16); // turn on backlight BLA_DDR |= _BV(BLA); BLA_PORT |= _BV(BLA); //LED_PORT &= ~_BV(LED); //write_buffer(buffer); }