Question: There will be three files in this project LabFPart 2 . java ( contains main method ) Pins.java ( contains pin definitions for the board

There will be three files in this project
LabFPart2.java (contains main method)
Pins.java (contains pin definitions for the board)
ButtonTask.java (defines what happens each time the Timer goes "bing!")
Develop the main method so that it can examine the status of the Button on Digital Input 6 using the task schedule system from Lab C. You will override the run() method in the TimerTask so that it can print the value of the button. The examination of the button should happen every 1000 milliseconds (1sec).
import org.flrmata4j.Pin; // Firmata
import org.firmata4j.firmata. FirmataDevice;
importjava.Io.IOException; // Bxceptions
import java.util.Timer; // Timer
import java.util.TimerTask; // Timer tasks,
public class LabFPartz |
public static void main(String[] args)
throws IOException, InterruptedException
1
var myUSBPort = "COM4"; // TO-DO: modify this!
// Create a FirmataDevice, start it and ensure Init is done.
...
??? Use getPin 0 to tell us which pin the button is connected to.
// Set the mode of this pin to Input.
// Button is Digital Input 6 on the Grove board (D6)
// This is exactly like with the LED in Part I, except thet
II 1. The Button is on digital input 6(not 4)
II 2. It's not Pin.Mode.OUTPUT .... it's INPUT:
// make a new task for the button
...
var task = new ButtonTask(button);
// Provide this task to the Timer.scheduleO method
??? and set the time to "no delay" and 1000ms. periods.
// this is like in Lab Cl
...
}
}
import org.firmata4j.Pin; // Firmata
import java.util.TimerTask; // Timer tasks.
public class ButtonTask extends TimerTask {
private final Pin myPin;
// The Constructor for ButtonTask
ButtonTask(Pin pin){
// Assign the externally-set "pin" to internal variable myPin
this. myn=n;
}
@Override
public void runO {
// Print this each time TimerTask runs (e.g. once per 1000ms.)
System.out.println("value : "+ myPin.getValueO);
}
}
Run the program. You should see 0's on the IntelliJ terminal when the button isn't pressed. You should see 1's in the terminal when the button is pressed.
Note: for me, button is located at D6 and LED is at D4.port is /dev/cu.usbserial-0001
 There will be three files in this project LabFPart2.java (contains main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!