Posts

Showing posts from September, 2018
project 1 song prepare song 1 Mario overworld theme #define NOTE_B2  123  #define NOTE_C3  131  #define NOTE_CS3 139  #define NOTE_D3  147  #define NOTE_DS3 156  #define NOTE_E3  165  #define NOTE_F3  175  #define NOTE_FS3 185  #define NOTE_G3  196  #define NOTE_GS3 208  #define NOTE_A3  220  #define NOTE_AS3 233  #define NOTE_B3  247  #define NOTE_C4  262  #define NOTE_CS4 277  #define NOTE_D4  294  #define NOTE_DS4 311  #define NOTE_E4  330  #define NOTE_F4  349  #define NOTE_FS4 370  #define NOTE_G4  392  #define NOTE_GS4 415  #define NOTE_A4  440  #define NOTE_AS4 466  #define NOTE_B4  494  #define NOTE_C5  523  #define NOTE_CS5 554  #define NOTE_D5  587  #define NOTE_DS5 622  #define NOTE_E5  659  #define NOT...
lab motor 9/20/2018 #include <Servo.h> const int SERVO=9; const int PIR=2;//The PIR is connected to pin 2 Servo myServo; void setup() {  myServo.attach(SERVO); } void loop() {   if ( digitalRead(PIR)==LOW)   {myServo.attach(180);   delay(15);}   else {  myServo.attach(0);  delay(15); }}
Image
lab sound 9/20/2018 int speakerPin = 9;  #define c 261 #define d 294 #define e 329 #define f 349 #define g 392 #define a 440 #define b 493 #define C 523 void setup() { }//close setup  void loop() {     tone(speakerPin, c, 250);   delay(500);   tone(speakerPin, c, 250);   delay(500);   tone(speakerPin, g, 250);   delay(500);   tone(speakerPin, g, 250);   delay(500);   tone(speakerPin, a, 250);   delay(500);   tone(speakerPin, a, 250);   delay(500);   tone(speakerPin, g, 700);   delay(1000);   tone(speakerPin, f, 250);   delay(500);   tone(speakerPin, f, 250);   delay(500);   tone(speakerPin, e, 250);   delay(500);   tone(speakerPin, e, 250);   delay(500);     tone(speakerPin, d, 250);   delay(500);   tone(speakerPin, d, 250);   delay(500); ...
 HW 9/19/2018 1 #include< stdio.h > #include < stdlib.h > int roll(); int main() { unsigned int i, n, seed,die1,die2,sum,Count= 0 ; double percent; printf( "Enter seed value: " ); scanf( "%d" , &seed); srand(seed); printf( "Enter number of rolls of Dice: " ); scanf( "%d" , &n); for (i= 0 ; i<n; i++){ die1 = roll(); die2 = roll(); sum = die1+die2; if (sum== 8 ){ Count++; }   } percent=(Count)* 100 /n; printf( "Number of rolls: %d\n" , n); printf( "Percent with sum of 8 : %4.2f %\n" , percent); return 0 ; } int roll(){ return rand()%( 1 ) ; } 2 #include < stdio.h > #include < stdlib.h > #include < math.h > #define e 2.718282 #define pi 3.141593 int main( void ) { int n_val; int n_val_fact( int n_val); printf( "Enter n:\n" ); scanf( "%d" ,&n_val...
lab                        9/18/2018 PIR and CdS control LED const int RLED=9;        //Red LED on pin 9 (PWM) const int LIGHT=1;       //Lght Sensor on analog pin 0 const int PIR=3; const int MIN_LIGHT=600; //Minimum expected light value const int MAX_LIGHT=700; //Maximum Expected Light value int val = 0;             //variable to hold the analog reading void setup() { pinMode(RLED, OUTPUT); //Set LED pin as output  pinMode(PIR, INPUT); } void loop() {  if (digitalRead(PIR) == LOW)  {     digitalWrite(RLED, LOW); val = analogRead(LIGHT);                     //Read the light sensor val = map(val, MIN_LIGHT, MAX_LIGHT, 255, 0);//Map the light rea...
HW 9/17/2018 1 #include < stdio.h > #include < math.h > int main( void ) { /*  Declare variables and function prototype.  */ double x1,y1,z1,x2,y2,z2; double angle( double x1, double y1, double z1, double x2, double y2, double z2); printf( "Enter value vectors " ); printf( "enter vector 1: \n" ); scanf( "%lf %lf %lf" ,&x1,&y1,&z1); printf( "enter vector 2: \n" ); scanf( "%lf %lf% lf" ,&x2,&y2,&z2); printf( "angle: %6.2f \n" , angle(x1,y1,z1,x2,y2,z2)); /*  Exit program.  */ return 0 ; } double angle( double x1, double y1, double z1, double x2, double y2, double z2) { /*  Declare variables.  */ double dot,n1,n2,gamma; /*  Compute angle between vectors.  */ dot = x1*x2 + y1*y2 + z1*z2; n1 = sqrt(x1*x1 + y1*y1 + z1*z1); n2 = sqrt(x2*x2 + y2*y2 + z2*z2); gamma = (acos(dot/(n1*n2))* 180 / 3.141593 ); /*  Compute a...
Image
lab 9/13/2018 const int hot = 77; //set hot parameter const int cold = 74; //set cold parameter void setup() { pinMode(A0, INPUT); //sensor pinMode(4, OUTPUT); //blue pinMode(3, OUTPUT); //green pinMode(2, OUTPUT); //red Serial.begin(9600); } void loop() { int sensor = analogRead(A0); float voltage = (sensor / 1023.0) * 5.0; float tempC = (voltage - 0.5) * 100; float tempF = (tempC * 1.8) + 32; Serial.print("temp: "); Serial.print(tempF); if (tempF < cold) { //cold digitalWrite(4, HIGH); digitalWrite(2, LOW); digitalWrite(3, LOW); Serial.println(" It's Cold."); } else if (tempF >= hot) { //hot digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(2, HIGH); Serial.println(" It's Hot."); } else { //fine digitalWrite(2, LOW); digitalWrite(3, HIGH); digitalWrite(4, LOW); Serial.println(" It's Fine."); } delay(10); }
HW 9/12/2018 1. Generate a table of conversions from feet per second to miles per hour. Start the ft/s column at 0 and increment by 5 ft/s. The last line should contain the value 100 ft/s. (Recall that 1 mi = 5280 ft)    #include < stdio.h > #include< math.h > #define PI 3.141593 int main( void ) {      double ft_s= 0 ;       double mi_h;          printf( "ft/s       to    mi/h \n" );          while (ft_s <= 100 )           {   mi_h = ft_s* 0.681 ;            printf( "%8.2f       %6.4f \n" ,ft_s,mi_h);             ft_s += 5 ;  }      ...