Question: Fill in missing lines of code for python. A Program to measure force using the Force - Sensitive Resistor ( FSR 4
Fill in missing lines of code for python. A Program to measure force using the
ForceSensitive Resistor FSR by Interlink Electronics"""
A FSR is a variable resistor that changes its resistance
in proportion to the force applied. FSR is a cheap
FSR and not highly accurate"""
#import time
from time import sleep
#Import Serial Programmable Interface module from the Adafruit SPI library
import AdafruitGPIO.SPI as SPI
#Import the MCP module from the Adafruit library
import AdafruitMCP
#Import GPIO library
import RPi.GPIO as io
#Define SPI Port and Device Identifiers
spiPort
#SPI Device Identifier
spiDevice
#Analog To Digital Object Global Variable
adc
#Channel Number to which the FSR is connected
chnFSR
A callback method to be called when the pushbutton is pressed
The callback method should measure the channel
def MeasureForcechannel:
Variable to store the dynamic resistance of FSR
initialized to the upper limit value"""
R
#Resistance in Series with FSR:
R
#Valid Maximum Force Sensor Resistance
MaxR
#Force Variable
F
#Define the maximum decimal value that can be measured on Channel of the ADC
MaxRawValue
Define the reference value of the input voltage signal connected
to Channel of the ADC"""
RefVolt
Variables to store the raw and corresponding values of the voltage
measured at Channel of the ADC"""
rawValue #Variable to store the raw value of the signal input to Channel
VoltageSum #Variable to store the sum of twenty five analog samples
AverageVoltage #Variable to store the average of twentyfive analog samples
Sampling twentyfive values over a period of seconds
and storing sum of the twenty five samples in the variable VoltageSum"""
Samples
for sample in rangeSamples:
Read the raw value from the Channel using the chnFSR variable
and adc object, and store in variable rawValue"""
Convert the rawValue to its corresponding analog Voltage using the
RefValue and add it to the VoltageSum variable"""
#Sleep for appropriate time to perform samples approximately in seconds
#Compute the average of the twentyfive samples and store in AverageVoltage
#Display the Average Voltage matching the sample format
Compute the resistance R of the Force Sensor using the Voltage divider formulae,
the RefVolt, Average Voltage and R
#Display the Force Sensing Resistor value matching the sample format
Compute the corresponding force using the straight line equations
only if the measured resistance of the FSR is less than or equal to ohms"""
You should first implement an ifelse to check whether the measured resistance
is less than kohms, and then inside the if condition implement
three if conditions corresponding to the three line segements"""
if namemain:
btnMeasureForce
iosetmodeioBCM
#Instantiate a ADC object using the global variable adc, spiPort, and spiDevice
setup the push button using the variable btnMeasureForce
connected to GPIO
setup the OS to detect an edge event at GPIO with the
callback method MeaureForce"""
inputPress Pushbutton to start measuring Force
or press any key to exit'
printExiting the program'
iocleanup
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
