What would be the missing parts to this code I already fille
What would be the missing parts to this code? I already filled a few.. working with adruino
code:
//Program template to perform Pre-Lab task (2)
int icount;
int StartButtonPin = 6;
int tensValue;
int onesValue;
unsigned long currentTimeStamp; //The millis() function
unsigned long endTimeStamp; //will return an unsigned long datatype so we remain consistent
boolean startButtonLast = LOW;
boolean startButtonCurrent = LOW;
boolean loopExit;
void setup()
{
Serial.begin(9600); // This line enables the serial monitor to be used for us to
pinMode(StartButtonPin, INPUT); // print the number of button presses for reading in the console.
//7-Segment LED Display
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void LEDDisplay(int count) //Can be re-used once you have this completed in the previous template.
{
switch(count) // Each case value also corresponds to the decimal value. Ex) Case 0 is decimal 0 and
//so on.
{
case 0:
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
break;
case 1:
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
break;
case 2:
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
break;
case 3:// when count value is 3 show ”3” on disp
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
break;
case 4:// when count value is 4 show”4” on disp
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
break;
case 5:// when count value is 5 show”5” on disp
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
break;
case 6:// when count value is 6 show”6” on disp
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
break;
case 7:// when count value is 7 show”7” on disp
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
break;
case 8:// when count value is 8 show”8” on disp
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
break;
case 9:// when count value is 9 show”9” on disp
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
break;
//Here add all the other cases as required..
default:
// Display letter \'d\'..
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}//switch-case ends
}//LED Display function end
//This function waits for button push and debounces button
boolean waitForButtonPush(boolean lastStartSwitchState)
{
//This function waits for a button push and also debounces it..
boolean currentStartSwitchState = digitalRead(StartButtonPin);
if(lastStartSwitchState != currentStartSwitchState) delay(20);
currentStartSwitchState = digitalRead(StartButtonPin);
return currentStartSwitchState;
}
void loop()
{
if(loopExit != 1)
{
Serial.println(\"Press button and continue pressing button as many times as you wish.\");
Serial.println(\"within a duration of 10 seconds: The total no of times pushed will be printed.\");
Serial.print(\'\ \'); //Newline
}
loopExit = 1; //Used as a flag for checking condition for displaying digits on the 7-segment LED
icount = 0;
LEDDisplay(10); //10 is chosen arbitrarily to force the default case in the switch-case structure
//which will turn the LED counter off when the button isn\'t pushed
startButtonCurrent = waitForButtonPush(startButtonLast);
//This is a debouncing measure for the button when it is pressed.
if(startButtonLast == LOW && startButtonCurrent == HIGH)
{
currentTimeStamp = millis(); // After button is pressed the current time the program has elapsed for
endTimeStamp = millis() + 10000; // is recorded with millis(), we know 10,000 ms = 10 seconds
while(currentTimeStamp < endTimeStamp)// While loop runs for 10 seconds according to the condition while
{ // also constantly checking for button presses and incrementing upon detection.
startButtonCurrent = waitForButtonPush(startButtonLast);
if(startButtonLast == LOW && startButtonCurrent == HIGH)
{
icount++;// Fill in missing line: Hint: Increment counter
Serial.println(\"Hit!..\");
}
startButtonLast = startButtonCurrent;//Re-assign current state to previous/last.
currentTimeStamp = millis(); // Updates elapsed time since while loop has started.
}//while
Serial.println(\"Stop!\");
Serial.print(\'\ \');
// Assumed that button cannot be hit more than 99 times..
tensValue = 9; //Fill in missing parts: Hint: extract 10\'s digit from icount
onesValue = 9; // Fill in missing parts: Hint: extract unit\'s digit from icount
while (loopExit == 1) // This while statement displays both digits for a 0-99
{ //count button push. it will display both digits then exit
Serial.print(\"Button was pushed \");
Serial.print(icount);
Serial.println(\" times.\");
Serial.print(\'\ \');
Serial.println(\"Waiting for 5 seconds...LOOK AT THE LED DISPLAY\ \");
delay(5000); // Wait for five seconds after stop message.
LEDDisplay(MISSING...); //Fill in missing part: Hint: Display the ten’s digit on the LED
delay(2000);
LEDDisplay(MISSING...); //Fill in missing part: Hint: Display the unit’s digit on the LED
delay(2000);
; /// Fill in missing line: Hint: forces exiting the while loop, use correct variable
}//while
startButtonLast = startButtonCurrent; //current state becomes last state for new repetition of the function loop()
}//if
}//loop
Solution
import java.util.*;
import java.awt.*;
import java.applet.*;
/* <applet code=DigitalClock width=300 height=150>
</applet>
*/
public class DigitalClock extends Applet implements Runnable
{
boolean stopFlag;
String display = \"\";
Thread th;
int hours, minutes, seconds;
public void init()
{
setBackground(Color.cyan);
setForeground(Color.blue);
stopFlag = true;
}
public void start() {
if(stopFlag)
{
th = new Thread(this);
stopFlag = false;
th.start();
}
}
public void stop() {
stopFlag = true;
th = null;
}
public void paint(Graphics g) {
g.setFont(new Font(\"Ariel\", Font.BOLD, 36));
display = String.valueOf(hours) + \":\" + String.valueOf(minutes) + \":\" + String.valueOf(seconds);
g.drawString(display, 50, 50);
g.drawString(String.valueOf(hours), 50, 100);
}
public void run()
{
for(;;) {
repaint(500);
Calendar cal = Calendar.getInstance();
hours = cal.get(Calendar.HOUR);
minutes = cal.get(Calendar.MINUTE);
seconds = cal.get(Calendar.SECOND);
if(stopFlag)
break;
try { Thread.sleep(500);}
catch(InterruptedException e) {
System.out.println(\"e\");
}
}
}
}




