init commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
.data
|
||||
array: .word 1, 2, 3, 4, 5, 6
|
||||
orig: .asciiz "Original array: "
|
||||
rev: .asciiz "\nReverse array: "
|
||||
|
||||
.text
|
||||
|
||||
main:
|
||||
|
||||
jal printOriginalArray
|
||||
jal printReverseArray
|
||||
|
||||
ori $v0, $0, 10 # system call code 10 for exit
|
||||
syscall # exit the program
|
||||
|
||||
reverse:
|
||||
bge $a0, $a1, done # if the start index is greater or equal to the end index, we are done
|
||||
|
||||
lw $t2, array($a0) # load the element at start index
|
||||
lw $t3, array($a1) # load the element at end index
|
||||
sw $t3, array($a0) # store the element from the end at the start index
|
||||
sw $t2, array($a1) # store the element from the start at the end index
|
||||
|
||||
addi $a0, $a0, 1 # increment the start index
|
||||
subi $a1, $a1, 1 # decrement the end index
|
||||
|
||||
b reverse # recursively reverse the remaining elements
|
||||
done:
|
||||
jr $ra # return to the caller
|
||||
|
||||
printOriginalArray:
|
||||
li $v0, 4
|
||||
la $a0, orig
|
||||
syscall
|
||||
|
||||
li $s0, 21 # limit of offsets for 6 elements in the array
|
||||
li $v0, 1 # syscall 1 to print an int
|
||||
li $t0, 0
|
||||
|
||||
origWhile:
|
||||
bge $t0, $s0 origDone # while the offset is less than 21
|
||||
lw $a0, array($t0) # load the next word in the array
|
||||
syscall # print
|
||||
|
||||
addi $t0, $t0, 4 # increment the offset by 4
|
||||
|
||||
b origWhile # return to start of while loop
|
||||
origDone:
|
||||
jr $ra # return to caller
|
||||
|
||||
printReverseArray:
|
||||
li $v0, 4
|
||||
la $a0, rev
|
||||
syscall
|
||||
|
||||
li $s0, -1 # lower limit of 6 offsets
|
||||
li $v0, 1 # syscall 1 to print an int
|
||||
li $t0, 20
|
||||
|
||||
revWhile:
|
||||
bge $s0, $t0 revDone # while the offset is less than 21
|
||||
lw $a0, array($t0) # load the next word in the array
|
||||
syscall # print
|
||||
|
||||
subi $t0, $t0, 4 # increment the offset by 4
|
||||
|
||||
b revWhile # return to start of while loop
|
||||
revDone:
|
||||
jr $ra # return to caller
|
||||
@@ -0,0 +1,75 @@
|
||||
.data
|
||||
firstNumPrompt: .asciiz "Enter g = "
|
||||
secondNumPrompt: .asciiz "Enter h = "
|
||||
thirdNumPrompt: .asciiz "Enter i = "
|
||||
fourthNumPrompt: .asciiz "Enter j = "
|
||||
|
||||
function: .asciiz "leaf_example(int g, int h, int i, int j) returns f \n"
|
||||
formula: .asciiz "f = (g + h) - (i + j) \n"
|
||||
end: .asciiz "f = "
|
||||
|
||||
.text
|
||||
|
||||
main:
|
||||
|
||||
# First prompt
|
||||
li $v0, 4 # Load immediate syscall value 4
|
||||
la $a0, firstNumPrompt # Load address into argument 0 (register $a0)
|
||||
syscall
|
||||
|
||||
# Read the first
|
||||
li $v0, 5 # system call 5 is for reading an integer
|
||||
syscall # integer value read is in $v0
|
||||
add $t0, $0, $v0 # copy the first num into $to
|
||||
|
||||
# Print the prompt for second num
|
||||
li $v0, 4 # Load immediate syscall value 4
|
||||
la $a0, secondNumPrompt # Load address into argument 0 (register $a0)
|
||||
syscall
|
||||
|
||||
# Read the second and add to total
|
||||
li $v0, 5 # system call 5 is for reading an integer
|
||||
syscall # integer value read is in $v0
|
||||
add $t0, $t0, $v0 # copy the first num into $to
|
||||
|
||||
# Print the prompt for third num
|
||||
li $v0, 4 # Load immediate syscall value 4
|
||||
la $a0, thirdNumPrompt # Load address into argument 0 (register $a0)
|
||||
syscall
|
||||
|
||||
# Read the third and subtract from total
|
||||
li $v0, 5 # system call 5 is for reading an integer
|
||||
syscall # integer value read is in $v0
|
||||
sub $t0, $t0, $v0 # copy the first num into $to
|
||||
|
||||
# Print the prompt for fourth num
|
||||
li $v0, 4 # Load immediate syscall value 4
|
||||
la $a0, fourthNumPrompt # Load address into argument 0 (register $a0)
|
||||
syscall
|
||||
|
||||
# Read the fourth and subtract from total
|
||||
li $v0, 5 # system call 5 is for reading an integer
|
||||
syscall # integer value read is in $v0
|
||||
sub $t0, $t0, $v0 # copy the first num into $to
|
||||
|
||||
# Print function header
|
||||
li $v0, 4 # Load immediate syscall value 4
|
||||
la $a0, function # Load address into argument 0 (register $a0)
|
||||
syscall
|
||||
|
||||
# Print formula header
|
||||
li $v0, 4 # Load immediate syscall value 4
|
||||
la $a0, formula # Load address into argument 0 (register $a0)
|
||||
syscall
|
||||
|
||||
# Print total
|
||||
li $v0, 4 # Load immediate syscall value 4
|
||||
la $a0, end # Load address into argument 0 (register $a0)
|
||||
syscall
|
||||
|
||||
# Print the total
|
||||
li $v0, 1
|
||||
la $a0, ($t0)
|
||||
syscall
|
||||
|
||||
nor
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
.data
|
||||
|
||||
firstNumPrompt: .asciiz "Enter the first number: "
|
||||
secNumPrompt: .asciiz "Enter the second number: "
|
||||
thirdNumPrompt: .asciiz "Enter the third number: "
|
||||
|
||||
sum: .asciiz "\nThe sum of the entered numbers is: "
|
||||
smallestNum: .asciiz "\nThe smallest number is: "
|
||||
largestNum: .asciiz "\nThe largest number is: "
|
||||
|
||||
initPrompt: .asciiz "Enter 3 whole numbers to display: the largest, the smallest, and the sum\n"
|
||||
tryAgainPrompt: .asciiz "\nWould you like to try again? (Enter any number for no and 0 for yes) "
|
||||
goodbye: .asciiz "\nThank you for using the program, see you next time!"
|
||||
|
||||
.text
|
||||
|
||||
main:
|
||||
|
||||
# Init prompt
|
||||
addi $v0, $0, 4
|
||||
la $a0, initPrompt
|
||||
syscall
|
||||
|
||||
# Load 0 into $s1 and $s0
|
||||
addi $s1, $s1, 0
|
||||
addi $s0, $s0, 0
|
||||
|
||||
while:
|
||||
bgtu $s0, $s1, done
|
||||
|
||||
# First prompt
|
||||
addi $v0, $0, 4
|
||||
la $a0, firstNumPrompt
|
||||
syscall
|
||||
|
||||
# Read the first
|
||||
addi $v0, $0, 5 # system call 5 is for reading an integer
|
||||
syscall # integer value read is in $v0
|
||||
add $s7, $0, $v0 # copy the width into $8
|
||||
|
||||
# Second prompt
|
||||
addi $v0, $0, 4
|
||||
la $a0, secNumPrompt
|
||||
syscall
|
||||
|
||||
# Read the second
|
||||
addi $v0, $0, 5
|
||||
syscall
|
||||
add $s6, $0, $v0
|
||||
|
||||
# Third prompt
|
||||
addi $v0, $0, 4
|
||||
la $a0, thirdNumPrompt
|
||||
syscall
|
||||
|
||||
# Read the third
|
||||
addi $v0, $0, 5
|
||||
syscall
|
||||
add $s5, $0, $v0
|
||||
|
||||
# Sum prompt
|
||||
addi $v0, $0, 4
|
||||
la $a0, sum
|
||||
syscall
|
||||
|
||||
# Add and print sum
|
||||
add $t0, $s7, $s6
|
||||
add $t0, $t0, $s5
|
||||
addi $v0, $0, 1
|
||||
add $a0, $0, $t0
|
||||
syscall
|
||||
|
||||
# Smallest prompt
|
||||
addi $v0, $0, 4
|
||||
la $a0, smallestNum
|
||||
syscall
|
||||
|
||||
# Find the smallest num
|
||||
bge $s5, $s6, else
|
||||
bge $s5, $s7, elseif
|
||||
add $t1, $0, $s5
|
||||
b next
|
||||
elseif:
|
||||
add $t1, $0, $s7
|
||||
|
||||
b next
|
||||
b next
|
||||
else:
|
||||
bge $s6, $s7, elseifif
|
||||
add $t1, $0, $s6
|
||||
b next
|
||||
elseifif:
|
||||
add $t1, $0, $s7
|
||||
b next
|
||||
next:
|
||||
|
||||
# Print the smallest num
|
||||
addi $v0, $0, 1
|
||||
add $a0, $0, $t1
|
||||
syscall
|
||||
|
||||
# Largest prompt
|
||||
addi $v0, $0, 4
|
||||
la $a0, largestNum
|
||||
syscall
|
||||
|
||||
# Find the largest num
|
||||
bge $s7, $s6, newElse
|
||||
bge $s6, $s5, newElseif
|
||||
add $t1, $0, $s5
|
||||
b newNext
|
||||
newElseif:
|
||||
add $t1, $0, $s6
|
||||
|
||||
b newNext
|
||||
b newNext
|
||||
newElse:
|
||||
bge $s7, $s5, newElseifif
|
||||
add $t1, $0, $s5
|
||||
b newNext
|
||||
newElseifif:
|
||||
add $t1, $0, $s7
|
||||
b newNext
|
||||
newNext:
|
||||
|
||||
# Print the smallest num
|
||||
addi $v0, $0, 1
|
||||
add $a0, $0, $t1
|
||||
syscall
|
||||
|
||||
# Prompt to start again
|
||||
addi $v0, $0, 4
|
||||
la $a0 , tryAgainPrompt
|
||||
syscall
|
||||
|
||||
# Start again
|
||||
addi $v0, $0, 5 # system call 5 is for reading an integer
|
||||
syscall # integer value read is in $v0
|
||||
add $s0, $0, $v0 # copy the width into $s0
|
||||
|
||||
b while
|
||||
|
||||
done:
|
||||
# Prompt to start again
|
||||
addi $v0, $0, 4
|
||||
la $a0 , goodbye
|
||||
syscall
|
||||
|
||||
exit:
|
||||
ori $v0, $0, 10 # system call code 10 for exit
|
||||
syscall # exit the program
|
||||
@@ -0,0 +1,77 @@
|
||||
# Assembly starter file for Exercise 1
|
||||
|
||||
.data
|
||||
width: .word
|
||||
height: .word
|
||||
area: .word
|
||||
perimeter: .word
|
||||
|
||||
widthPrompt: .asciiz "Enter width (integer):\n"
|
||||
heightPrompt: .asciiz "Enter height (integer):\n"
|
||||
areaIs: .asciiz "Rectangle's area is "
|
||||
perimeterIs: .asciiz "Rectange's perimeter is "
|
||||
newline: .asciiz "\n"
|
||||
|
||||
|
||||
|
||||
.text
|
||||
|
||||
main:
|
||||
# Print the prompt for width
|
||||
addi $v0, $0, 4 # system call 4 is for printing a string
|
||||
la $a0, widthPrompt # address of widthPrompt is in $a0
|
||||
syscall # print the string
|
||||
|
||||
# Read the width
|
||||
addi $v0, $0, 5 # system call 5 is for reading an integer
|
||||
syscall # integer value read is in $v0
|
||||
add $8, $0, $v0 # copy the width into $8
|
||||
|
||||
# Print the prompt for height
|
||||
addi $v0, $0, 4 # system call 4 is for printing a string
|
||||
la $a0, heightPrompt # address of heightPrompt is in $a0
|
||||
syscall # print the string
|
||||
|
||||
# Read the height
|
||||
addi $v0, $0, 5 # system call 5 is for reading an integer
|
||||
syscall # integer value read is in $v0
|
||||
add $9, $0, $v0 # copy the height into $9
|
||||
|
||||
# Calculate area
|
||||
mult $8, $9 # multiply width * height
|
||||
mflo $10 # bring the product into $10 (assume hi not needed)
|
||||
|
||||
# Calculate perimeter
|
||||
add $11, $8, $9 # Add length + width
|
||||
add $11, $11, $9 # Add another width
|
||||
add $11, $11, $8 # Add another length
|
||||
|
||||
# Print "Rectangle's area is "
|
||||
addi $v0, $0, 4 # system call 4 is for printing a string
|
||||
la $a0, areaIs # address of areaIs string is in $a0
|
||||
syscall # print the string
|
||||
|
||||
# Print the calculated area (in $10)
|
||||
addi $v0, $0, 1 # system call 1 is for printing an integer
|
||||
add $a0, $0, $10 # bring the area value from $10 into $a0
|
||||
syscall # print the integer
|
||||
|
||||
# Print a newline
|
||||
addi $v0, $0, 4 # system call 4 is for printing a string
|
||||
la $a0, newline # address of areaIs string is in $a0
|
||||
syscall # print the string
|
||||
|
||||
# Print "Rectangle's perimeter is "
|
||||
addi $v0, $0, 4 # System call 4 to print a string
|
||||
la $a0, perimeterIs # address of perimeterIs string is in $a0
|
||||
syscall # print the string
|
||||
|
||||
# Print the calculated perimeter (in $11)
|
||||
addi $v0, $0, 1 # system call 1 is for printing an integer
|
||||
add $a0, $0, $11 # bring the area value from $11 into $a0
|
||||
syscall # print the integer
|
||||
|
||||
# Exit from the program
|
||||
exit:
|
||||
ori $v0, $0, 10 # system call code 10 for exit
|
||||
syscall # exit the program
|
||||
@@ -0,0 +1,53 @@
|
||||
.data
|
||||
welcomeMessage: .asciiz "Welcome to a MIPS assembly Fibonacci Sequence calculator!\nThis will calculate the nth term of the Fibonacci Sequence.\n"
|
||||
prompt: .asciiz "Enter a number (n, input n > 2) to find the nth term:"
|
||||
foundTerm: .asciiz "The nth term is: "
|
||||
|
||||
.text
|
||||
|
||||
main:
|
||||
li $v0, 4 # syscall 4 is to print a string
|
||||
la $a0, welcomeMessage # store the ascii string in register a0
|
||||
syscall # print
|
||||
|
||||
jal getInput # get the user input
|
||||
|
||||
jal fibonacci # calculate the nth fibonacci term
|
||||
move $a0, $v0 # move the returned term to register a0
|
||||
li $v0, 1 # syscall 1 is to print an int
|
||||
syscall # print
|
||||
|
||||
ori $v0, $0, 10 # system call code 10 for exit
|
||||
syscall # exit the program
|
||||
|
||||
getInput:
|
||||
li $v0, 4 # syscall 4 is to print a string
|
||||
la $a0, prompt # store the ascii string in register a0
|
||||
syscall # print
|
||||
|
||||
li $v0, 5 # syscall 5 is for reading an int
|
||||
syscall # read an int from the user
|
||||
move $a0, $v0 # load input into register a0
|
||||
|
||||
jr $ra # return to caller
|
||||
|
||||
fibonacci:
|
||||
move $s1, $a0 # Copy the nth term
|
||||
li $t0, 2 # Counter
|
||||
li $t1, 0 # Prev value
|
||||
li $t2, 1 # Current value
|
||||
li $t3, 0 # Next value
|
||||
|
||||
while:
|
||||
bge $t0, $s1, done # While the counter is less than n
|
||||
add $t3, $t1, $t2 # Sum the previous and current values and save in register t3
|
||||
move $t1, $t2 # Shift current value to previous value
|
||||
|
||||
move $t2, $t3 # Shift next value to current value
|
||||
addi $t0, $t0, 1 # Increment counter
|
||||
|
||||
b while # Jump back to start of while loop
|
||||
|
||||
done:
|
||||
move $v0, $t2 # Move current value to register v0
|
||||
jr $ra # Return to caller
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
LAB: NOT
|
||||
Author: Samuel Gardner
|
||||
*/
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(PIN2, INPUT);
|
||||
pinMode(PIN3, INPUT);
|
||||
pinMode(PIN4, OUTPUT);
|
||||
pinMode(PIN5, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (!digitalRead(PIN2))
|
||||
{
|
||||
digitalWrite(PIN4, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(PIN4, LOW);
|
||||
}
|
||||
if (digitalRead(PIN3))
|
||||
{
|
||||
digitalWrite(PIN5, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(PIN5, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
LAB: AND/OR
|
||||
Author: Samuel Gardner
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(PIN2, INPUT);
|
||||
pinMode(PIN3, INPUT);
|
||||
pinMode(PIN4, INPUT);
|
||||
pinMode(PIN5, INPUT);
|
||||
pinMode(PIN6, OUTPUT);
|
||||
pinMode(PIN7, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (!digitalRead(PIN2) || !digitalRead(PIN3))
|
||||
{
|
||||
Serial.print("pin6 should be high");
|
||||
digitalWrite(PIN6, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("pin6 should be low");
|
||||
digitalWrite(PIN6, LOW);
|
||||
}
|
||||
if (!digitalRead(PIN4) && !digitalRead(PIN5))
|
||||
{
|
||||
Serial.print("pin7 should be high");
|
||||
digitalWrite(PIN7, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("pin7 should be low");
|
||||
digitalWrite(PIN7, LOW);
|
||||
}
|
||||
}
|
||||
*/
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
Truth Table
|
||||
Switch 1: start/stop
|
||||
Switch 1, 2: increment until 9, buzzer sounds
|
||||
Switch 1, 4: decrement until 0, buzzer sounds
|
||||
*/
|
||||
|
||||
//Output Pins for Display
|
||||
int pinArray[7] = {8, 9, 10, 11, 12, 13, 6}; //{pinA, pinB, pinC, pinD, pinE, pinF, pinG};
|
||||
|
||||
//Input Pins from Dip Switch
|
||||
int pin0 = 0;
|
||||
int pin1 = 1;
|
||||
int pin2 = 2;
|
||||
int pin3 = 3;
|
||||
|
||||
//Output pin for Buzzer
|
||||
int buzzPin = 7;
|
||||
|
||||
//Digital Display values
|
||||
byte values[10][7] = {
|
||||
{1, 1, 1, 1, 1, 1, 0}, //number 0
|
||||
{0, 1, 1, 0, 0, 0, 0}, //number 1
|
||||
{1, 1, 0, 1, 1, 0, 1}, //number 2
|
||||
{1, 1, 1, 1, 0, 0, 1}, //number 3
|
||||
{0, 1, 1, 0, 0, 1, 1}, //number 4
|
||||
{1, 0, 1, 1, 0, 1, 1}, //number 5
|
||||
{1, 0, 1, 1, 1, 1, 1}, //number 6
|
||||
{1, 1, 1, 0, 0, 0, 0}, //number 7
|
||||
{1, 1, 1, 1, 1, 1, 1}, //number 8
|
||||
{1, 1, 1, 0, 0, 1, 1} //number 9
|
||||
};
|
||||
|
||||
//Value to know where the counter is in the countdown(up)
|
||||
int curVal = 0;
|
||||
|
||||
//Boolean to know if the buzzer is triggered or not
|
||||
bool buzzed = false;
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
//Set up for 7 seg display
|
||||
for(int x = 0; x < 7; x++)
|
||||
{
|
||||
pinMode(pinArray[x], OUTPUT);
|
||||
}
|
||||
|
||||
//Set up for Dip Switch
|
||||
pinMode(pin0, INPUT);
|
||||
pinMode(pin1, INPUT);
|
||||
pinMode(pin2, INPUT);
|
||||
pinMode(pin3, INPUT);
|
||||
|
||||
//Set up for buzzer pin
|
||||
pinMode(buzzPin, OUTPUT);
|
||||
//Sets Display to current value (Will start at 0)
|
||||
writeNum(curVal);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
//Remains in loop if Start/Stop is triggered
|
||||
while(digitalRead(pin3) == 1){}
|
||||
//Waits 1 second
|
||||
delay(1000);
|
||||
|
||||
//Increases value to next level as long as it is less than 9, incrementer is triggered, and decrementer is not triggered
|
||||
if(curVal < 9 && digitalRead(pin2) == 0 && digitalRead(pin0) != 0)
|
||||
{
|
||||
curVal++;
|
||||
writeNum(curVal);
|
||||
|
||||
//Triggers buzzer if value is 9 after incrementing
|
||||
if(curVal == 9)
|
||||
{
|
||||
writeNum(curVal);
|
||||
alarmBuzzer();
|
||||
}
|
||||
}
|
||||
//Decreases value to next level as long as it is greater than 0, decrimenter is triggered, and incrementer is not triggered
|
||||
else if(curVal > 0 && digitalRead(pin0) == 0 && digitalRead(pin2) != 0)
|
||||
{
|
||||
curVal--;
|
||||
writeNum(curVal);
|
||||
|
||||
//Triggers buzzer if value is 0 after decrementing
|
||||
if(curVal == 0)
|
||||
{
|
||||
writeNum(curVal);
|
||||
alarmBuzzer();
|
||||
}
|
||||
}
|
||||
//If buzzer is triggered, waits for 3rd switch to be hit to turn off before continuing
|
||||
while(buzzed && digitalRead(pin1) == 1){}
|
||||
|
||||
//After 3rd switch is hit, turns buzzer off
|
||||
if(buzzed)
|
||||
{
|
||||
disarmBuzzer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void alarmBuzzer()
|
||||
{
|
||||
if(digitalRead(pin1) == 1)
|
||||
{
|
||||
buzzed = true;
|
||||
digitalWrite(buzzPin, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void disarmBuzzer()
|
||||
{
|
||||
buzzed = false;
|
||||
digitalWrite(buzzPin, LOW);
|
||||
}
|
||||
|
||||
|
||||
//Writes number to display
|
||||
void writeNum(int n) {
|
||||
for(int x = 0; x < 7; x++)
|
||||
{
|
||||
digitalWrite(pinArray[x], values[n][x]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
int time = 9; // default timer
|
||||
|
||||
int zero[] = {
|
||||
2,3,4,5,6,7,8
|
||||
};
|
||||
|
||||
int one[] = {
|
||||
3,4
|
||||
};
|
||||
|
||||
int two[] = {
|
||||
2,3,6,7,9
|
||||
};
|
||||
|
||||
int three[] = {
|
||||
2,3,4,6,9
|
||||
};
|
||||
|
||||
int four[] = {
|
||||
3,4,8,9
|
||||
};
|
||||
|
||||
int five[] = {
|
||||
2,4,6,8,9
|
||||
};
|
||||
|
||||
int six[] = {
|
||||
8,7,6,4,9
|
||||
};
|
||||
|
||||
int seven[] = {
|
||||
2,3,4
|
||||
};
|
||||
|
||||
int eight[] = {
|
||||
2,3,4,6,7,8,9
|
||||
};
|
||||
|
||||
int nine[] = {
|
||||
2,3,4,9,8
|
||||
};
|
||||
|
||||
void setup() {
|
||||
for(int i = 2; i < 10; i++) {
|
||||
pinMode(i, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (time == 0) { // Display 0.
|
||||
for(int i = 0; i < 7; i++) {
|
||||
digitalWrite(zero[i], HIGH);
|
||||
}
|
||||
} else if(time == 1) { // Display 1
|
||||
for(int i = 0; i < 2; i++) {
|
||||
digitalWrite(one[i], HIGH);
|
||||
}
|
||||
} else if(time == 2) { // Display 2
|
||||
for(int i = 0; i < 5; i++) {
|
||||
digitalWrite(two[i], HIGH);
|
||||
}
|
||||
} else if(time == 3) { // Display 3
|
||||
for(int i = 0; i < 5; i++) {
|
||||
digitalWrite(three[i], HIGH);
|
||||
}
|
||||
} else if(time == 4) { // Display 4
|
||||
for(int i = 0; i < 4; i++) {
|
||||
digitalWrite(four[i], HIGH);
|
||||
}
|
||||
} else if(time == 5) { // Display 5
|
||||
for(int i = 0; i < 5; i++) {
|
||||
digitalWrite(five[i], HIGH);
|
||||
}
|
||||
} else if(time == 6) { // Display 6
|
||||
for(int i = 0; i < 5; i++) {
|
||||
digitalWrite(six[i], HIGH);
|
||||
}
|
||||
} else if(time == 7) { // Display 7
|
||||
for(int i = 0; i < 3; i++) {
|
||||
digitalWrite(seven[i], HIGH);
|
||||
}
|
||||
} else if(time == 8) { // Display 8
|
||||
for(int i = 0; i < 7; i++) {
|
||||
digitalWrite(eight[i], HIGH);
|
||||
}
|
||||
} else if(time == 9) { // Display 9
|
||||
for(int i = 0; i < 5; i++) {
|
||||
digitalWrite(nine[i], HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
time--;
|
||||
delay(1000);
|
||||
|
||||
// reset
|
||||
for(int i = 2; i < 10; i++) {
|
||||
digitalWrite(i, LOW);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user