il T-Mobile 7:33 PM canvas.csun.edu Homework_3.pd Download ZOOMt ME435L Das Lear
ID: 2293984 • Letter: I
Question
il T-Mobile 7:33 PM canvas.csun.edu Homework_3.pd Download ZOOMt ME435L Das Learning Objective: Arduino Input, Arrays, Random numbers Problem: Build the circuit given below and write a program that prints a random lab commandment in Serial Monitor as below when button is pressed. Output: Your Today's c Have a Nice Day! t is: Have Great Work Ethics Gr Circuit: In Hints: Use digitalRead() function to read from pin 2. Use random() function to get a random number. Add a delay of 1s. Li Res Big Question: What is the purpose of the 10KQ resistor?Explanation / Answer
Arduino code:-
long randNumber;
int val = 0; // variable to store the read value
void setup()
{
Serial.begin(9600);
// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));
pinMode(2, INPUT);
}
void loop()
{
val = digitalRead(2);
if (val == HIGH)
{
randNumber = random(10);
if (randNumber == 0)
{
Serial.println("Today's commandment is: Thou shalt not use a computer to harm other people.");
}
if (randNumber == 1)
{
Serial.println("Today's commandment is: Thou shalt not interfere with other people's computer work.");
}
if (randNumber == 2)
{
Serial.println("Today's commandment is: Thou shalt not snoop around in other people's computer files.");
}
if (randNumber == 3)
{
Serial.println("Today's commandment is: Thou shalt not use a computer to steal.");
}
if (randNumber == 4)
{
Serial.println("Today's commandment is: Thou shalt not use a computer to bear false witness.");
}
if (randNumber == 5)
{
Serial.println("Today's commandment is: Thou shalt not copy or use proprietary software for which you have not paid.");
}
if (randNumber == 6)
{
Serial.println("Today's commandment is:Thou shalt not use other people's computer resources without authorization or proper compensation.");
}
if (randNumber == 7)
{
Serial.println("Today's commandment is: Thou shalt not use a computer to harm other people.");
}
if (randNumber == 8)
{
Serial.println("Today's commandment is: Thou shalt not appropriate other people's intellectual output.");
}
if (randNumber == 9)
{
Serial.println("Today's commandment is: Thou shalt think about the social consequences of the program you are writing or the system you are designing.");
}
if (randNumber == 10)
{
Serial.println("Today's commandment is: Thou shalt always use a computer in ways that ensure consideration and respect for your fellow humans.");
}
}
delay(1000);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.