Answer to Question #266461 in C for Rick

Question #266461

Create a small Arduino project in tinkerCAD.


The project must make use of at least the following:


● Any 1 of the following analog sensors: TMP36, Flex sensor, Photoresistor, or Force Sensor.


AND


● Any 2 of the following Digital input devices: Pushbutton, Slide switch, or DIP switch.


AND


● Any 1 of the following Digital output devices: LED, or Piezo Buzzer.


AND


● Any 1 of the following PWM output devices: DC Motor, Hobby gearmotor, RGB LED.


AND


● A 16x2 LCD display




In you program you must make use of the following:


● analogRead(), digitalRead(),analogWrite(), digitalWrite()


● if statements and if else statements, (i.e. testing the value of a sensor)


● at least 1 while loop


● at least 1 for loop


● an array


● variables


● The LCD display


● arithmetic ( + , - , * , / , % ) and compound operators (+=,-=,*=,/=,%=)


● Comparison and Logical operators


1
Expert's answer
2021-11-15T17:28:05-0500
# include<iostream>
using namespace std;
const int sPin = A0; 
const int lPin = 6; 
const int iPin = 10; 
const int buttonPin = 3; 
int sensorMin = 1023; 
int sensorMax = 0; 
int sensorValue = 0;
// An array
int timer = 90; 
int ledPins[] = {




 1, 4, 5, 8, 7, 3
}; 
int pinCount = 8; 
 




void setup() {




for (int thisPin = 2; thisPin < 8; thisPin++) {




 pinMode(thisPin, OUTPUT);
 pinMode(iPin, OUTPUT);




 pinMode(lPin, OUTPUT);




 pinMode(buttonPin, INPUT);




 }
}




void loop() {




//DigitalRead
 while (digitalRead(buttonPin) == HIGH) {




 calibrate();




 
}


 digitalWrite(iPin, LOW);
 sensorValue = analogRead(sPin);
 sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
 sensorValue = constrain(sensorValue, 0, 255);
 analogWrite(lPin, sensorValue);
}




void calibrate() {
 digitalWrite(iPin, HIGH);
 sensorValue = analogRead(sPin);
 
 //if statements
 if (sensorValue > sensorMax) {
 sensorMax = sensorValue;




 }
 if (sensorValue < sensorMin) {
 sensorMin = sensorValue;




 
 }
 else{
 sensorMin=0;
 }
}
void lCDDisplay()
{
 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS