Answer to Question #264842 in C++ for ursula

Question #264842

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-12T07:16:17-0500
# include<iostream>
using namespace std;
const int SenPin = A0;       
const int ledPin = 6;     
const int IndiLedPin = 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(IndiLedPin, OUTPUT);


    pinMode(ledPin, OUTPUT);


    pinMode(buttonPin, INPUT);


  }
}


void loop() {


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


    calibrate();


  
}




//DigitalWrite
  digitalWrite(IndiLedPin, LOW);
  sensorValue = analogRead(SenPin);//analogRead
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
  sensorValue = constrain(sensorValue, 0, 255);
  analogWrite(ledPin, sensorValue);//analogWrite
}


void calibrate() {
  digitalWrite(IndiLedPin, HIGH);
  sensorValue = analogRead(SenPin);
  
  //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