Card Reader

Card Reader

Hardware

This is simple – just some wheels geared down 1:3 to move the card in and out over the color sensor. The touch sensor senses whether the card is being pushed in. and I also had a touch sensor and motor for the door but that was only to prove  that the card reader worked.

Program

I programmed using ROBOTC. I wanted to re-teach myself ROBOTC and I really like it. I’m never back to NXT-G. ROBOTC is just easier once you learn it. I was having trouble having it read the card  (and tell me the code) because it was too inaccurate – it would give me the wrong colors a lot  so instead it only figures out if it is the correct card.

You can download the code here.

Card reader update

Card reader update

If you follow me on Facebook or Google+ then you probably now that I’m building a card reader.

Program is done for the card reader part – it doesn’t actually know what the card reads – It just knows if it’s the correct card or not, so it would need to be completely reprogrammed to accepted different colors or order of colors – I attempted to make one that read card then figure out if it is correct after but it was not working correctly. I’m not entirely sure what i’m going to use this for yet – I was thinking of  making a car that only worked after the card was scanned, but I’ve been having trouble building a car around this.
It was all coded in ROBOTC.
Pictures below the code.
You can download this code here.

#pragma config(Sensor, S1,     Touch,          sensorTouch)
#pragma config(Sensor, S2,     Power,          sensorTouch)
#pragma config(Sensor, S3,     Color,          sensorCOLORFULL)
#pragma config(Motor,  motorA,          Cardmover,     tmotorNXT, PIDControl, reversed, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
task main()
{
	nxtDisplayCenteredBigTextLine(2, "Remove");
	nxtDisplayCenteredBigTextLine(4, "Card");
	while(SensorValue(Power) == 0)
	{
		motor[motorB] = runStateHoldPosition;
		motor[motorC] = runStateHoldPosition;
		while(SensorValue(Touch) == 1)
		{
			motor[Cardmover] = -100;
			wait10Msec(10);
	  	PlayTone(758, 2);
		}
		motor[Cardmover] = 0;
		motor[Cardmover] = 0;
		eraseDisplay();
		nxtDisplayCenteredBigTextLine(2, "Insert");
		nxtDisplayCenteredBigTextLine(4, "Card");
		while(SensorValue(Touch) == 0)
		{
		}
		eraseDisplay();
		motor[Cardmover] = 75;
		while(SensorValue(Color) == BLACKCOLOR)
		{
		}
		if(SensorValue(Color) == REDCOLOR)
		{
			while(SensorValue(Color) == REDCOLOR)
			{
			}
			if(SensorValue(Color) == WHITECOLOR)
			{
				while(SensorValue(Color) == WHITECOLOR)
				{
				}
				if(SensorValue(Color) == YELLOWCOLOR)
				{
					while(SensorValue(Color) == YELLOWCOLOR)
					{
					}
					if(SensorValue(Color) == WHITECOLOR)
					{
						while(SensorValue(Color) == WHITECOLOR)
						{
						}
						if(SensorValue(Color) == REDCOLOR)
						{
							nxtDisplayCenteredTextLine(2, "Access Granted");
							motor[Cardmover] = -100;
						 	wait10Msec(200);
						 	motor[Cardmover] = 0;
						 	while(SensorValue(Touch) == 1)
							{
								motor[Cardmover] = -100;
								wait10Msec(10);
						  	PlayTone(758, 2);
							}
							motor[Cardmover] = 0;
					 	}
					 	else
						{
							  nxtDisplayCenteredTextLine(3, "access denied");
							  	motor[Cardmover] = -100;
							 	wait10Msec(200);
							 	motor[Cardmover] = 0;
								}
							 	}
							 	else
							 	{
							   nxtDisplayCenteredTextLine(3, "access denied");
							   	motor[Cardmover] = -100;
							 		wait10Msec(200);
							 		motor[Cardmover] = 0;
							 		}
						 			}
						 			else
							 		{
							   	nxtDisplayCenteredTextLine(3, "access denied");
							   	motor[Cardmover] = -100;
							 		wait10Msec(200);
							 		motor[Cardmover] = 0;
							 		}
							 		}
							 		else
							 		{
							   		nxtDisplayCenteredTextLine(3, "access denied");
							   		motor[Cardmover] = -100;
							 			wait10Msec(200);
							 			motor[Cardmover] = 0;
							 		}

					}
	}
}