Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- struct opCode
- {
- unsigned int digits : 3;
- };
- struct ALU_Driver
- {
- int A;
- int B;
- opCode operation;
- };
- ALU_Driver arr[8];
- int Result_Array[8];
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- int pushed = 0;
- int readBtn(){
- pushed = analogRead(0);
- if(pushed == 1023) return 1;
- if(pushed == 1021) return 2;
- return pushed;
- }
- int index = 0;
- int btn = 0;
- void Print(int index){
- lcd.setCursor(0, 0);
- String temp = "";
- switch (arr[index].operation.digits) {
- case 000:
- temp="+";
- break;
- case 001:
- temp="-";
- break;
- case 010:
- temp="<<";
- break;
- case 011:
- temp=">>";
- break;
- case 100:
- temp=">>";
- break;
- case 101:
- temp="&";
- break;
- case 110:
- temp="|";
- break;
- case 111:
- temp="^";
- break;
- default:
- break;
- }
- lcd.print(arr[index].A + temp + arr[index].B + "=" + Result_Array[index]);
- }
- void setup() {
- lcd.begin(16, 2);
- arr[0].A=3;
- arr[0].B=5;
- arr[0].operation.digits=000;
- arr[1].A=13;
- arr[1].B=7;
- arr[1].operation.digits=001;
- arr[2].A=22;
- arr[2].B=3;
- arr[2].operation.digits=010;
- arr[3].A=33;
- arr[3].B=1;
- arr[3].operation.digits=011;
- arr[4].A=33;
- arr[4].B=-1;
- arr[4].operation.digits=100;
- arr[5].A=23;
- arr[5].B=32;
- arr[5].operation.digits=101;
- arr[6].A=37;
- arr[6].B=20;
- arr[6].operation.digits=110;
- arr[7].A=17;
- arr[7].B=28;
- arr[7].operation.digits=111;
- int i=0;
- for (i=0;i<8;i++) {
- switch (arr[i].operation.digits) {
- case 000:
- Result_Array[i]=arr[i].A + arr[i].B;
- break;
- case 001:
- Result_Array[i]=arr[i].A - arr[i].B;
- break;
- case 010:
- Result_Array[i]=arr[i].A << arr[i].B;
- break;
- case 011:
- Result_Array[i]=arr[i].A >> arr[i].B;
- break;
- case 100:
- if(arr[i].B<0){
- arr[i].B*=-1;;
- Result_Array[i]=arr[i].A << arr[i].B;
- }else{
- Result_Array[i]=arr[i].A >> arr[i].B;
- }
- break;
- case 101:
- Result_Array[i]=arr[i].A & arr[i].B;
- break;
- case 110:
- Result_Array[i]=arr[i].A | arr[i].B;
- break;
- case 111:
- Result_Array[i]=arr[i].A ^ arr[i].B;
- break;
- default:
- break;
- }
- }
- Print(index);
- }
- void loop() {
- btn = readBtn();
- if(btn == 1){
- lcd.clear();
- index--;
- if(index < 0)
- index = 7;
- delay(150);
- Print(index);
- }else if(btn == 2){
- lcd.clear();
- index = (index + 1) % 8;
- delay(150);
- Print(index);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement