示例#1
0
文件: Geigerct.c 项目: Bediko/r0ket
static uint8_t mainloop() {
	uint32_t ioconbak = IOCON_PIO1_11;

	uint32_t volatile oldCount=IntCtr;
	uint32_t perMin=0; // counts in last 60 s
	uint32_t startTime=_timectr;
	uint8_t button;
		IOCON_PIO1_11 = 0;
		while (1) {
			//GPIO_GPIO0DATA&=~(1<<11);
			IOCON_PIO1_11 = ioconbak;
			GPIO_GPIO1DATA &= ~(1 << 7);
			GPIO_GPIO1DATA &= ~(1 << 11);
			lcdClear();

			lcdPrintln("   Geiger");
			lcdPrintln("   Counter");
			// ####
			for (int i=0; i< (14*( _timectr-startTime))/(60*100);i++) {
				lcdPrint("#");
			}

			lcdPrintln("");
			lcdPrintln("Counts:");
			lcdPrint(" ");
			lcdPrintInt(IntCtr);
			lcdPrintln(" total");
			lcdPrint(" ");
			lcdPrintInt(  perMin);
			lcdPrintln("/min");
			// remember: We have a 10ms Timer counter
			if ((startTime+60 *100 ) < _timectr) {
				// dumb algo: Just use last 60 seconds count
				perMin=IntCtr-oldCount;
				startTime=_timectr;
				oldCount=IntCtr;
			}
			lcdRefresh();
			delayms(42);
			button = getInputRaw();

			if (button != BTN_NONE) {
				delayms(23);// debounce and wait till user release button
				while (getInputRaw()!=BTN_NONE) delayms(23);
				break;
			}
		}
		IOCON_PIO1_11 = ioconbak;
		return button;

}
示例#2
0
/** reaction.c
 *  First l0dable for my r0ket
 *  Improvement is welcome
 *
 * AUTHOR: hubba
*/
void ram(void)
{
    char x = gpioGetValue(RB_LED1);
    int rand_wait = 0;
    int react_time=0;
    int start_time = 0;
    int end_time = 0;

    gpioSetValue (RB_LED1,0);           //upperleft LED off
    lcdClear();
    lcdPrintln("Hello");
    lcdPrintln(GLOBAL(nickname));
    lcdPrintln("ReACTION");
    lcdRefresh();
    delayms(500);
    while(1)
    {
        react_time = 0;
        lcdPrintln("Press ENTER if ");
        lcdPrintln("LED is on!");
        lcdRefresh();
        rand_wait = getRandom();
        rand_wait = rand_wait%50;
        rand_wait = 40 + rand_wait*4;        // Minimum pause time is 400ms
        for(int i =0; i<=rand_wait; i++)     //directly calling delayms(rand_wait) didn't work
        {
            delayms(10);
        }
        gpioSetValue (RB_LED1, 1);          //upperleft LED ON
        getInputWaitRelease();
        start_time = getTimer()*(SYSTICKSPEED);
        while (getInputWait() != BTN_ENTER);    //wait for user input
        {

        }
        end_time =  getTimer()*(SYSTICKSPEED);
        react_time = end_time - start_time;     //measure  used time
        lcdClear();
        lcdPrint("Needed ");
        lcdPrintInt(react_time);
        lcdPrintln(" ms");
        lcdPrintln("DOWN: Exit");
        lcdPrintln("0ther: New game");
        lcdRefresh();
        gpioSetValue (RB_LED1,0);           //upperleft LED off

        getInputWaitRelease();
        if(getInputWait() ==  BTN_DOWN)     //Check for Exit/new game
        {
            gpioSetValue (RB_LED1, x);      //upperleft LED as before l0dable executed
            return;
        }
    }
    /* NEVER LAND HERE */
    lcdPrintln("Flow-Error");
    lcdRefresh();
    return;
};
示例#3
0
文件: funk.c 项目: Bediko/r0ket
void f_cfg(void){
    struct NRF_CFG config;

    nrfconfig cfg=&config;

    nrf_config_get(cfg);

    lcdPrint("ch:");lcdPrintInt( cfg->channel ); lcdNl();
    lcdPrint("nr:");lcdPrintInt( cfg->nrmacs ); lcdNl();

    lcdPrint("0:");
    lcdPrintCharHex(cfg->mac0[0]);
    lcdPrintCharHex(cfg->mac0[1]);
    lcdPrintCharHex(cfg->mac0[2]);
    lcdPrintCharHex(cfg->mac0[3]);
    lcdPrintCharHex(cfg->mac0[4]);
    lcdNl();
    lcdPrint("1:");
    lcdPrintCharHex(cfg->mac1[0]);
    lcdPrintCharHex(cfg->mac1[1]);
    lcdPrintCharHex(cfg->mac1[2]);
    lcdPrintCharHex(cfg->mac1[3]);
    lcdPrintCharHex(cfg->mac1[4]);
    lcdNl();
    lcdPrint("2345:");
    lcdPrintCharHex(cfg->mac2345[0]);
    lcdPrintCharHex(cfg->mac2345[1]);
    lcdPrintCharHex(cfg->mac2345[2]);
    lcdPrintCharHex(cfg->mac2345[3]);
    lcdNl();
    lcdPrint("tx:");
    lcdPrintCharHex(cfg->txmac[0]);
    lcdPrintCharHex(cfg->txmac[1]);
    lcdPrintCharHex(cfg->txmac[2]);
    lcdPrintCharHex(cfg->txmac[3]);
    lcdPrintCharHex(cfg->txmac[4]);
    lcdNl();
    lcdPrint("len:");
    lcdPrintCharHex(cfg->maclen[0]);
    lcdPrintCharHex(cfg->maclen[1]);
    lcdPrintCharHex(cfg->maclen[2]);
    lcdPrintCharHex(cfg->maclen[3]);
    lcdPrintCharHex(cfg->maclen[4]);
    lcdNl();
};
示例#4
0
文件: config.c 项目: andrmuel/r0ket
int saveConfig(void){
    FIL file;            /* File object */
    UINT writebytes;
    UINT allwrite=0;
    int res;
#if DEBUG
    lcdClear();
#endif

	res=f_open(&file, CONFFILE, FA_OPEN_ALWAYS|FA_WRITE);
#if DEBUG
	lcdPrint("create:");
	lcdPrintln(f_get_rc_string(res));
#endif
	if(res){
		return 1;
	};

    CONF_ITER{
        res = f_write(&file, &the_config[i].value, sizeof(uint8_t), &writebytes);
        allwrite+=writebytes;
        if(res){
#if DEBUG
            lcdPrint("write:");
            lcdPrintln(f_get_rc_string(res));
#endif
            return 1;
        };
    };
#if DEBUG
	lcdPrint("write:");
	lcdPrintln(f_get_rc_string(res));
	lcdPrint(" (");
	lcdPrintInt(allwrite);
	lcdPrintln("b)");
#endif

	res=f_close(&file);
#if DEBUG
	lcdPrint("close:");
	lcdPrintln(f_get_rc_string(res));
#endif
	if(res){
		return 1;
	};
	return 0;
}
示例#5
0
文件: util.c 项目: Bediko/r0ket
// //# MENU lcdread
void lcdrtest(void){
    lcdClear();
    lcdPrint("ID1:"); lcdPrintInt(lcdRead(128+64+16+8  +2  )); lcdNl();
    lcdPrint("ID2:"); lcdPrintInt(lcdRead(128+64+16+8  +2+1)); lcdNl();
    lcdPrint("ID3:"); lcdPrintInt(lcdRead(128+64+16+8+4    )); lcdNl();
    lcdPrint("ID4:"); lcdPrintInt(lcdRead(128+64+16+8+4  +1)); lcdNl();
    lcdPrint("Tmp:"); lcdPrintInt(lcdRead(128+64+16+8+4+2  )); lcdNl(); 
    lcdPrint("VM:"); lcdPrintInt(lcdRead(128+64+16+8+4+2+1)); lcdNl(); 
//    lcd_select(); mylcdWrite(0,128+32+8+4+1); lcd_deselect();
    delayms(10);
    lcdInit();
    lcdRefresh();
    while(!getInputRaw())delayms(10);
};
示例#6
0
文件: funk.c 项目: Bediko/r0ket
void f_recv(void){
    __attribute__ ((aligned (4))) uint8_t buf[32];
    int len;
    do{

        lcdClear();
        len=nrf_rcv_pkt_time_encr(1000,sizeof(buf),buf,enctoggle?testkey:NULL);

        if(len==0){
            lcdPrintln("No pkt (Timeout)");
        };
        lcdPrint("Size:");lcdPrintInt(len);lcdNl();
        lcdPrint("1:");lcdPrintIntHex( *(int*)(buf+ 0) ); lcdNl();
        lcdPrint("2:");lcdPrintIntHex( *(int*)(buf+ 4) ); lcdNl();
        lcdPrint("3:");lcdPrintIntHex( *(int*)(buf+ 8) ); lcdNl();
        lcdPrint("4:");lcdPrintIntHex( *(int*)(buf+12) ); lcdNl();

        len=crc16(buf,14);
        lcdPrint("crc:");lcdPrintShortHex(len); lcdNl();
        lcdDisplay();
    }while ((getInputRaw())==BTN_NONE);

};
示例#7
0
int main() {
	int G = 0, keyInterval = 1;
	float rms, power = 0, setPower = 3.0;
	unsigned char keyBuf;
	bool adRefresh = true, pwrValueRefresh = true, gainValueRefresh = true;
	bool enAGC = true, atLimit = false;
//	isAdj = false;

	lcdInit();
	ec11Init();
	adInit();
	lcdBacklit(true);

	lcdPrintStr("Design: CX Wang");
	lcdLocate(2, 1);
	lcdPrintStr("Initializing..");
	idelay_s(5);
	lcdClear();

	for(;;) {
		if(pwrValueRefresh || gainValueRefresh) {
			/*
			 * Display
			 */
			lcdWrite(0x0c,0,1); // Turn cursor off
			if(pwrValueRefresh) {
				pwrValueRefresh = false;

				lcdLocate(1, 0);
				lcdPrintStr("PWR: ");
				if(power < 9.94)
					lcdPrintFloat(power + 0.05, 3, 1); //For rounding
				else
					lcdPrintStr(">10");
				lcdPrintStr("W");
				if(enAGC) {
					lcdPrintStr("/");
					lcdPrintFloat(setPower, 3, 1);
					lcdPrintStr("W");
				}
			}
			if(gainValueRefresh) {
				gainValueRefresh = false;
				lcdLocate(0, 1);
				lcdPrintStr("Gain: ");
				lcdPrintInt(G, 4);
				if(G == 0 || G == 1023 * ADNUM) {
					lcdLocate(15, 1);
					lcdPrintStr("*");
					atLimit = true;
				} else if(atLimit) {
					atLimit = false;
					lcdLocate(15, 1);
					lcdPrintStr(" ");
				}

			}
			if(enAGC)
				lcdLocate(15, 0);
			else
				lcdLocate(10, 1);
			lcdWrite(0x0e,0,1); // Turn cursor on
		}

		/*
		 * Adjustment
		 */
		rms = (float)adcRead(0) * 10.0 / 1024.0;
		power = rms * rms / 8.0;
		if(enAGC) {
			if(power < setPower) {
				G += fabs(power - setPower) * 10;//imax(1, fabs(power - setPower) * 10);
				if(G > 1023 * ADNUM)
					G = 1023 * ADNUM;
				adRefresh = true;
				gainValueRefresh = pwrValueRefresh = true;
//				isAdj = true;
			} else if(power > setPower + 0.02) {
				/* Ensure precision for power higher than 0.4watt and reduce oscillation
				 * got x1.03 retired */
				G -= fabs(power - setPower) * 10;//imax(1, fabs(power - setPower) * 10);
				if(G < 0)
					G = 0;
				adRefresh = true;
				gainValueRefresh = pwrValueRefresh = true;
//				isAdj = true;
			} else if(setPower < 0.05) {
				G = 0;
				adRefresh = true;
				gainValueRefresh = pwrValueRefresh = true;
			}
//			else if(isAdj) {
//				isAdj = false;
//				pwrValueRefresh = pwrValueRefresh = true;
//			}
		} else if(fabs(power - setPower) > 0.05){
			setPower = power;
			if(setPower > 7.50)
				setPower = 7.50;
			pwrValueRefresh = true;
		}
		if(adRefresh) {
			adRefresh = false;
			adSetGain(G);
		}

		if((keyBuf = ec11Check()) == 2) {
			if(enAGC) {
				setPower += 0.10;
				if(setPower > 7.50)
					setPower = 7.50;
				pwrValueRefresh = true;
			} else {
				G += keyLevel(keyInterval);
				if(G > 1023 * ADNUM)
					G = 1023 * ADNUM;
				gainValueRefresh = adRefresh = true;
				if(keyInterval < 1000)
					keyInterval += 50;
			}
		} else if(keyBuf == 1) {
			if(enAGC) {
				setPower -= 0.10;
				if(setPower < 0)
					setPower = 0;
				pwrValueRefresh = true;
			} else {
				G -= keyLevel(keyInterval);
				if(G < 0)
					G = 0;
				gainValueRefresh = adRefresh = true;
				if(keyInterval < 1000)
					keyInterval += 50;
			}
		} else if(keyBuf & 0b100) {
			enAGC = !enAGC;
			lcdClear();
			pwrValueRefresh = gainValueRefresh = true;
		}
		if(keyInterval > 1)
			keyInterval--;
	}
}
示例#8
0
static uint8_t mainloop() {
	uint32_t volatile oldCount = BusIntCtr;
	uint32_t loopCount=BusIntCtr;
	perMin = 0; // counts in last 60 s
	uint32_t minuteTime = _timectr;
	startTime = minuteTime;
	uint8_t button;
	//usbHIDInit();
	while (1) {
		LED_OFF;
		if (loopCount != BusIntCtr) {
			loopCount=BusIntCtr;
			LED_ON;
			IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_GPIO;
			gpioSetDir(RB_LED3,gpioDirection_Output ) ;
			gpioSetValue(RB_LED3, 1);
			if (!GLOBAL(positionleds) ) {
				gpioSetValue(RB_LED2,1);
				gpioSetValue(RB_LED0,1);
			}
		} else {
			if (gpioGetValue(RB_PWR_CHRG) || !GLOBALchargeled) {
				gpioSetDir(RB_LED3,gpioDirection_Input ); // only when not charging..
				}
				if (!GLOBAL(positionleds) ) {
					gpioSetValue(RB_LED0,0);
					gpioSetValue(RB_LED2,0);
				}
			}

		lcdClear();
		//lcdPrintln("   Geiger");
		//lcdPrintln("   Counter");


		memcpy(&lcdBuffer[RESX*RESY_B-sizeof(Header_Invers)],Header_Invers,sizeof(Header_Invers));
		lcdPrintln("");
		lcdPrintln("");
		// ####
		for (int i = 0; i < (14 * (_timectr - minuteTime)) / (60 * 100); i++) {
			lcdPrint("#");
		}
		lcdPrintln("");
		lcdPrint(" ");
		lcdPrintInt(BusIntCtr);
		lcdPrint(" in ");
		lcdPrintInt((_timectr - startTime) / 100);
		lcdPrintln("s");
		lcdPrint(" ");
		lcdPrintInt(perMin);
		lcdPrintln(" cpm");
		{
			uint32_t equivalent = nanoSievertPerH(perMin)+5; // letzte stelle runden
			lcdPrint(" ");
			lcdPrintInt(equivalent / 1000);
			lcdPrint(".");
			lcdPrintInt((equivalent % 1000) / 100);
			lcdPrintInt((equivalent % 100) / 10);
			//lcdPrintInt((equivalent % 10));
			lcdPrintln(" uSv/h");

		}
		//getGeigerMeshVal();
		lcdPrintln("");
		if (gpioGetValue(RB_PWR_CHRG)){
			uint32_t voltage=GetVoltage();
			if (voltage >= GOOD_VOLTAGE) {
				lcdPrintln("Bat: [++++] ");
			} else if (voltage >= HALF_VOLTAGE) {
				lcdPrintln("Bat: [ooo ] ");
			} else if (voltage >= MIN_SAFE_VOLTAGE) {
				lcdPrintln("Bat: [==  ]  ");
			} else if (voltage >= CRIT_VOLTAGE) {
				lcdPrintln("Bat: [-   ] L");
			} else {
				lcdPrintln("Battery: CRIT!");
			}
		} else {
			    lcdPrintln("Bat: Charging");
		}
		// remember: We have a 10ms Timer counter
		if ((minuteTime + 60 * 100) <= _timectr) {
			// dumb algo: Just use last 60 seconds count
			perMin = BusIntCtr - oldCount;
			minuteTime = _timectr;
			oldCount = BusIntCtr;
			//transmitGeigerMeshVal(perMin,minuteTime / (100));
		}
		lcdRefresh();
		delayms_queue_plus(42, 0);
		button = getInputRaw();
		if (button != BTN_NONE) {
			break;
		}

	}
	//usbHidDisconnect();
	return button;
}
示例#9
0
int main() {
	int G = 512;
	float rms, power = 0, setPower = 3.0;
	unsigned char keyBuf;
	bool adRefresh = true, pwrValueRefresh = true, gainValueRefresh = true;
	bool enAGC = true, atLimit = false, isAdj = false;

	lcdInit();
	ec11Init();
	adInit();
	lcdBacklit(true);

	for(;;) {
		if(pwrValueRefresh || gainValueRefresh) {
			/*
			 * Display
			 */
			lcdWrite(0x0c,0,1); // Turn curson off
			if(pwrValueRefresh) {
				pwrValueRefresh = false;

				lcdLocate(1, 0);
				lcdPrintStr("PWR: ");
				lcdPrintFloat(power, 3, 1);
				lcdPrintStr("W");
				if(enAGC) {
					lcdPrintStr("/");
					lcdPrintFloat(setPower, 3, 1);
					lcdPrintStr("W");
				}
			}
			if(gainValueRefresh) {
				gainValueRefresh = false;
				lcdLocate(0, 1);
				lcdPrintStr("Gain: ");
				lcdPrintInt(G, 4);
				if(G == 0 || G == 2046) {
					lcdLocate(15, 1);
					lcdPrintStr("*");
					atLimit = true;
				} else if(atLimit) {
					atLimit = false;
					lcdLocate(15, 1);
					lcdPrintStr(" ");
				}

			}
			if(enAGC)
				lcdLocate(15, 0);
			lcdWrite(0x0e,0,1); // Turn cursor on
		}

		rms = (float)adcRead(0) * 10.0 / 1024.0;
		power = rms * rms / 8.0;
		if(enAGC) {
			if((!isAdj && power < setPower) || (isAdj && power < setPower + 0.1)) {
				if(G < 2047 - 1)
					G++;
				adRefresh = true;
				gainValueRefresh = true;
				isAdj = true;
			} else if((!isAdj && power > setPower + 0.03) || (isAdj && power > setPower + 0.02)) {
				/* Ensure precision for power higher than 0.4watt and reduce oscillation
				 * got x1.03 retired */
				if(G > 0)
					G--;
				adRefresh = true;
				gainValueRefresh = true;
				isAdj = true;
			} else if(isAdj) {
				isAdj = false;
				pwrValueRefresh = true;
			}
		}
		if(adRefresh) {
			adRefresh = false;
			adSetGain(G);
		}

		if((keyBuf = ec11Check()) == 2) {
			if(enAGC) {
				setPower += 0.10;
				pwrValueRefresh = true;
			} else {
				G++;
				gainValueRefresh = true;
			}
		} else if(keyBuf == 1) {
			if(enAGC) {
				setPower -= 0.10;
				pwrValueRefresh = true;
			} else {
				G--;
				gainValueRefresh = true;
			}
		} else if(keyBuf & 0b100) {
			enAGC = !enAGC;
			lcdClear();
			pwrValueRefresh = gainValueRefresh = true;
		}
	}
}
示例#10
0
void ram (void) {
	uint8_t key = BTN_RIGHT, button;
	lcdClear();
	while (1) {	
		switch (key) {
			case BTN_ENTER:
				// exit
				return;
			case BTN_RIGHT:
				if (direction != DIRECTION_LEFT)
					direction = DIRECTION_RIGHT;
			break;
			case BTN_UP:
				if (direction != DIRECTION_DOWN)
					direction = DIRECTION_UP;
			break;
			case BTN_LEFT:
				if (direction != DIRECTION_RIGHT)
					direction = DIRECTION_LEFT;
			break;
			case BTN_DOWN:
				if (direction != DIRECTION_UP)
					direction = DIRECTION_DOWN;
			break;
				//Default: No keystroke received. Assuming last keystroke.
		}
		point newendpoint = snake.endpoint;
		shiftPoint (&newendpoint, direction);
		bool resetBacon = false;
		if (newendpoint.x == bacon.x && newendpoint.y == bacon.y) {
			growBuf (&snake, direction);
			resetBacon = true;
		} else {
			setGamePixel(snake.startpoint.x, snake.startpoint.y, 0);
			shiftBuf (&snake, direction);
		}

		if (getGamePixel(snake.endpoint.x, snake.endpoint.y))
			break;
		setGamePixel(snake.endpoint.x, snake.endpoint.y, 1);

		while (resetBacon) {
			bacon.x = getRandom() % GAME_WIDTH;
			bacon.y = getRandom() % GAME_HEIGHT;
			if (!getGamePixel(bacon.x, bacon.y))
				resetBacon = false;
		}
		
		drawFood (bacon.x, bacon.y);
		lcdRefresh();
		key = BTN_NONE;
		
		for (i=0; i < ( TIME_PER_MOVE / 50 ); ++i) {
			delayms(50);
			if ((button = getInputRaw()) != BTN_NONE)
				key = button;
		}

	}
	
	// Game ended, show results
	lcdClear();
	lcdNl();
	lcdPrintln("Game Over");
	lcdPrintln("Your score:");
	lcdPrintInt(getLength(&snake) - INITIAL_LENGTH + 1);
	lcdNl();
	lcdPrintln("Press any key");
	lcdPrintln("to continue.");
	lcdRefresh();
	delayms(500);
	while(getInputRaw() == BTN_NONE)
		delayms(25);
}
示例#11
0
文件: tedliz.c 项目: blubkatze/r0ket
void ram() {

	int raw_key, key;
	int i, j;
	int score, lastlvl, linec;

	new_stone();
	new_stone();

	// epmty grid
	for(i = 0; i < GRID_HEIGHT; i++)
		for(j = 0; j < GRID_WIDTH; j++)
			grid[i][j] = 0;
	
	// prepare screen
	lcdClear();
	for(i = 0; i < 96; i++) {
		lcdSetPixel(i, 2, 1);
		lcdSetPixel(i, 65, 1);
	}
	for(i = 3; i < 65; i++) {
		lcdSetPixel(2, i, 1);
		lcdSetPixel(35, i, 1);
		lcdSetPixel(93, i, 1);
	}

	score = 0;
	lastlvl=0;
	linec = 0;

	lcdSetCrsr(37,25);
	lcdPrint("level: 0");

	lcdSetCrsr(37,40);
	lcdPrint("score:");
	lcdSetCrsr(37,50);
	lcdPrintInt(0);
	
	for(;;) {

		// handle input
		raw_key = getInputRaw();
		key = 0;
		for(i = 0; i < 5; i++) {
			if(raw_key & (1 << i)) {
				if(!key_rep[i] || key_rep[i] == KEY_REPEAT_DELEAY) key |= 1 << i;
				key_rep[i] += key_rep[i] < KEY_REPEAT_DELEAY;
			}
			else key_rep[i] = 0;
		}


		// rotate
		if(key & BTN_UP) {
			i = rot;
			rot = (rot << 1) % 15;
			if(collision(0)) rot = i;
		}

		// horizontal movement
		i = x_pos;
		x_pos += !!(key & BTN_RIGHT) - !!(key & BTN_LEFT);
		if(i != x_pos && collision(0)) x_pos = i;

		// vertical movement
		ticks++;
		if(key & BTN_DOWN || ticks >= ticks_per_drop) {
			ticks = 0;
			y_pos++;
			if(collision(0)) {
				y_pos--;

				// check for game over
				if(collision(1)) return;

				// copy stone to grid
				int x, y;
				for(y = 0; y < 4; y++) {
					for(x = 0; x < 4; x++) {
						if(stones[stone][(x << 2) + y] & rot)
							grid[y + y_pos][x + x_pos] = 1;
					}
				}

				// check for complete lines
				for(y = 0; y < GRID_HEIGHT; y++) {
					for(x = 0; x < GRID_WIDTH; x++)
						if(!grid[y][x]) break;

					if(x == GRID_WIDTH) {

						lines++;
						linec++;	// temporary line counter
						ticks_per_drop = STARTING_SPEED - lines / 10;
						if(ticks_per_drop < 1) ticks_per_drop = 1;

						for(i = y; i > 0; i--)
							for(x = 0; x < GRID_WIDTH; x++)
								grid[i][x] = grid[i - 1][x];

						switch(linec){
							case 1:
								score += 40*(lines/10+1);
								break;
							case 2:
								score += 100*(lines/10+1);
								break;
							case 3:
								score += 300*(lines/10+1);
								break;
							case 4:
								score += 1200*(lines/10+1);
								break;
						} 
					}
				}

				if (lines/10>lastlvl){
					lcdSetCrsr(37,25);
					lcdPrint("level: ");
					lcdPrintInt(lines/10);
				}
				if (linec > 0){
					lcdSetCrsr(37,40);
					lcdPrint("score:");
					lcdSetCrsr(37,50);
					lcdPrintInt(score);
				}
				
				lastlvl=lines/10;
				linec = 0;
				
				// get a new stone
				new_stone();
			}
		}

		draw_grid();
        lcdDisplay();
		delayms(TICK_LENGTH);
	}
	return;
}