int main(void)
{
	uchar analogVal;
	uchar digitalVal;

	if(wiringPiSetup() == -1){
		printf("setup wiringPi failed !");
		return 1; 
	}

	pinMode(ADC_CS,  OUTPUT);
	pinMode(ADC_CLK, OUTPUT);
	pinMode(RAIN,    INPUT);

	while(1){
		pinMode(ADC_DIO, OUTPUT);
		analogVal = get_ADC_Result();
		digitalVal = digitalRead(RAIN);

		printf("%d\n",analogVal);

		if(digitalVal == 0){
			printf("    *****************\n");
			printf("    * !! RAINING !! *\n");
			printf("    *****************\n\n");
		}
		delay(500);
	}

	return 0;
}
void micISR(void)
{
	uchar analogVal;

	printf("voice in \n");
	
	pinMode(ADC_DIO, OUTPUT);

	analogVal = get_ADC_Result();
	printf("Current analog : %d\n", analogVal);
}
Exemple #3
0
int main(void)
{
  uchar analogVal = 0;
  uchar illum = 0;

  // when initialize wiring failed, print message to screen
  if(wiringPiSetup() == -1){
    fprintf(stderr, "setup wiringPi failed!");
    return 1;
  }

  pinMode(ADC_CS,  OUTPUT);
  pinMode(ADC_CLK, OUTPUT);
  pinMode(ADC_DIO, OUTPUT);

  analogVal = get_ADC_Result();

  // most times when analogVal = 0 the brightness sensor isn't connected to the Raspberry
  if(analogVal == 0)
  {
    delay(10);
    analogVal = get_ADC_Result();
    if(analogVal == 0){
      fprintf(stderr, "brightness sensor maybe not connected!");
      return 3;
    }
  }

  if(analogVal <= 210 && dataState == DATA_GOOD)
  {
    illum = 210 - analogVal;
  }
  else if (analogVal > 210 && dataState == DATA_GOOD)
  {
    illum = 0;
  }
  fprintf(stdout, "%d", illum);
  fflush(stdout);

  return 0;
}
Exemple #4
0
void micISR(void)
{
    uchar analogVal;

    pinMode(ADC_DIO, OUTPUT);

    analogVal = get_ADC_Result();
    if (current_number == sizeof(numbers) - 1) {
        FILE* f = fopen("a.pcm", "wb");
        fwrite(numbers, 1, sizeof(numbers), f);
        fclose(f);
        exit(0);
    }
    numbers[current_number] = analogVal;
    current_number++;
}
Exemple #5
0
void micISR(void)
{
	uchar analogVal;

	//printf("voice in \n");
	
	pinMode(ADC_DIO, OUTPUT);

	analogVal = get_ADC_Result();
	if (current_number == sizeof(numbers) - 1) {
		FILE* f = fopen("a.wav", "wb");
		fwrite(numbers, 1, sizeof(numbers), f);
		fclose(f);
		exit(0);
	}
	numbers[current_number] = analogVal;
	//printf("%i", current_number);
	//printf("%i \n", analogVal);
	current_number++;
	//printf("Current analog : %d\n", analogVal);
}
Exemple #6
0
int main(void)
{
    uchar analogVal;
    uchar illum;

    if(wiringPiSetup() == -1) { //when initialize wiring failed,print messageto screen
        printf("setup wiringPi failed !");
        return 1;
    }

    pinMode(ADC_CS,  OUTPUT);
    pinMode(ADC_CLK, OUTPUT);

    while(1) {
        pinMode(ADC_DIO, OUTPUT);

        analogVal = get_ADC_Result();
        illum = 210 - analogVal;
        printf("Current illumination : %d\n", illum);
        delay(500);
    }

    return 0;
}
int main(void)
{
	uchar analogVal;
	uchar temp;

	if(wiringPiSetup() == -1){ //when initialize wiring failed,print messageto screen
		printf("setup wiringPi failed !");
		return 1; 
	}

	pinMode(ADC_CS,  OUTPUT);
	pinMode(ADC_CLK, OUTPUT);

	while(1){
		pinMode(ADC_DIO, OUTPUT);

		analogVal = get_ADC_Result();
		temp = 140 - analogVal;
		printf("Current temperature : %d\n", temp);
		delay(500);
	}

	return 0;
}
int main(void)
{
	uchar analogVal;
	uchar mag;;

	if(wiringPiSetup() == -1){ //when initialize wiring failed,print messageto screen
		printf("setup wiringPi failed !");
		return 1; 
	}

	pinMode(ADC_CS,  OUTPUT);
	pinMode(ADC_CLK, OUTPUT);

	while(1){
		pinMode(ADC_DIO, OUTPUT);

		analogVal = get_ADC_Result();
		mag = 210 - analogVal;
		printf("Current intensity of magnetic field : %d\n", mag);
		delay(500);
	}

	return 0;
}
/**
* Program pooling a directory, and doing a scheduling.
**/
int main (int argc, char** argv)
{

	initPins();
	adc_init();
	lcd_init();
	
	/** The status does not exist at the launch of the schduler prgram*/
	clearFile();
	int pid=readPid();	
	stopIfPidExists(pid);
	writePid();
	
	SetChrMode();
	int nbSecond;
	int remainingSeconds;
	uchar intensity;
	uchar tmpintensity;
    int i;
	int valueInFile;
	time_t whenItsComplete ;
	char timestr[7];
	
	pinMode (RELAY_IN, OUTPUT);
	// Permanent loop checking file.
	int cycle=0;
	
	
	while(1){
		valueInFile=getCoundownValue();
		#ifndef PROD
		printf("pause:%d,valueInFile:%d\n",pauseSt,valueInFile);
		#endif
	
		if(valueInFile>=0){
			nbSecond=valueInFile;
		// The countdown
			whenItsComplete = time(NULL)+nbSecond;
			remainingSeconds=whenItsComplete-time(NULL);
		}
		else{remainingSeconds=-1;}
		#ifndef PROD
		printf("nbsecond:%d\n",nbSecond);
		#endif
	
	
		do {
	
	   /**
	   * Do a regular reset of the LCD
	   **/
		if(cycle%500==0){
		 lcd_init();
		}
		else if(cycle%60==0){
			resetLcd();
		}
		/**
		* Write the remaining seconds
		**/
		if(cycle%60==0){
		 writeRemaining(remainingSeconds);
		}
		

		/**
		* Increment only if not in pause (Cycle increments will be at the end of the cycle loop.
		**/	

		
		updateStandbyStatus();
		cycle++;

		
		
		if(remainingSeconds>-1){
		if(pauseSt==IS_RUNNING){
				remainingSeconds=whenItsComplete-time(NULL);
		}else{
			    whenItsComplete=remainingSeconds+time(NULL);
		}


				openRelay();
				if(lastImmobileState==0||(time(NULL)-lastImmobileState)<NBSECONDBEFORECREENSHUTDOWN){
				digitalWrite (TRANSISTOR, LOW);
				}
				else{
				digitalWrite (TRANSISTOR, HIGH);
				}
				int seconds=remainingSeconds%60;
				int hours=remainingSeconds/3600;
				int minutes=remainingSeconds/60%60;
			
				sprintf(timestr,"%02d:%02d:%02d",hours,minutes,seconds);
					
				goHome();
				lcd_text(timestr);
				#ifndef PROD
				printf("%s\n",timestr);
				#endif
				sleep(1);
		}
			/**
			* Block measuring intensity
			*/
			if(cycle%20==0){
				intensity=get_ADC_Result();
				#ifndef PROD
				printf("Intensite: %d\n",intensity);
				#endif
			}
			#ifndef PROD
			printf("Remaining seconds %d,cycle=%d\n",remainingSeconds,cycle);
			#endif

	} while ( remainingSeconds>0&& !isFilePresent());
	
		#ifndef PROD
	//	printf("Sortie boucle décompte\n");
		#endif
			
		/**
		* Every 10 ccyle there is a full reset of the screen. Otherwise it is  light reset.
		**/
	
		if(cycle%100==0){
			lcd_init();
		}
		nbSecond=0;
		/**
		*
		**/
		if(valueInFile==NO_FILE){
			goHome();
			closeRelay();
			digitalWrite (TRANSISTOR, HIGH);
			lcd_text("Expire    " );
			#ifndef PROD
			printf("Expire\n");
			#endif
		}
			else if(valueInFile==TV_ON){
			goHome();
			openRelay();
			digitalWrite (TRANSISTOR, LOW);
			lcd_text("Tele on      " );
			}
		else if(valueInFile==TV_OFF){
			goHome();
			digitalWrite (TRANSISTOR, HIGH);
			closeRelay();
			lcd_text("Tele off      " );
		}
		sleep(3);
	}
}