Skip to main content

Posts

Showing posts with the label finish

Day 5: Analog Sensors | Repetition Statements

#include <stdio.h> #include <math.h> int main(void){ float pi=3.14159265; float wave1p,wave2p,wave1h,wave2h; float wavelength1,wavelength2,newp,timeinc; float newheight; //Read period and wave height for wave 1 printf("Input the period and wave height of wave 1\n"); scanf("%f %f\n",&wave1p,&wave1h); //Read period and wave height for wave 2 printf("Input the period and wave height of wave 2\n"); scanf("%f %f\n",&wave2p,&wave2h); //Compute and print wavelength for each wave wavelength1=5.13*pow(wave1p,2); wavelength2=5.13*pow(wave2p,2); printf("Wave 1 Wavelength: %5.3f \n Wave 2 Wavelength: %5.3f \n",wavelength1,wavelength2); //Set new period to product of wave periods newp=wave1p*wave2p; timeinc=newp/200; float time=0, wavemax=0, steps=0, sum; while(steps<=199) { newheight=(wave1h+wave2h)*sin(2*pi*time*(1/newp)); if (newheight>wavemax) { wavemax=...

Day 4: RGB Nightlight | Algorithm Development, Conditional Expressions, Selection Statements

Hardware: RGB Nightlight const int red=11; const int green=10; const int blue=9; const int button=4; boolean lastbutton=LOW; boolean currentbutton=LOW; int ledMode=0; void setup() {   // put your setup code here, to run once:   pinMode(button,INPUT);   pinMode(red,OUTPUT);   pinMode(green,OUTPUT);   pinMode(blue,OUTPUT); } boolean debounce(boolean last) {   boolean current=digitalRead(button);   if(last!=current)   {     delay(5);     current=digitalRead(button);   }   return current; } void setMode(int mode) {   //RED   if(mode==1)   {     digitalWrite(red,HIGH);     digitalWrite(green,LOW);     digitalWrite(blue,LOW);   }   if(mode==2)   {     //orange     digitalWrite(red,HIGH);     analogWrite(green,40);     digitalWrite(blue,LOW);...

Day 2: Math Operations, Overflow and Underflow, Printf and Scanf

Lab Today we started with our first Arduino lab. We first wanted to make one LED on a breadboard blink, then get 4 LEDs to blink. I was able to do this successfully using the code below. void setup() {   // put your setup code here, to run once: pinMode(11, OUTPUT); pinMode(10, OUTPUT); pinMode(9, OUTPUT); pinMode(3, OUTPUT); } void loop() {   // put your main code here, to run repeatedly:   digitalWrite(11, HIGH);      delay(500);   digitalWrite(11,LOW);   digitalWrite(10,HIGH);      delay(500);   digitalWrite(10,LOW);   digitalWrite(9,HIGH);      delay(500);   digitalWrite(9,LOW);      delay(100);   digitalWrite(11, HIGH);   digitalWrite(3,HIGH);   digitalWrite(10,HIGH);   digitalWrite(9,HIGH);   delay(100);   digitalWrite(11, LOW);   digitalWrite(3,LOW);   digitalWrite(10,LOW);   digitalWrite(9,LOW); ...