hi
- User
hi
- Assistant
Hello! How can I assist you today?
- Assistant
Yes, how can I help you?
- User
code in C language a motion sensor
- Assistant
Here is an example code for a motion sensor using the C programming language:
#include<stdio.h> #include<conio.h> #include<wiringPi.h> #define LED 1 #define MOTION_SENSOR 0 int main() { int status = 0; wiringPiSetup(); pinMode(LED, OUTPUT); pinMode(MOTION_SENSOR, INPUT); while(1) { status = digitalRead(MOTION_SENSOR); if(status == HIGH) { digitalWrite(LED, HIGH); printf("\nMotion detected!"); } else { digitalWrite(LED, LOW); printf("\nNo motion detected!"); } delay(1000); } return 0; }In this code, the
wiringPilibrary is used to interface with the Raspberry Pi's GPIO pins. The motion sensor is connected to pin 0 and the LED is connected to pin 1.The
digitalReadfunction is used to read the value from the motion sensor pin. If it detects motion, the LED is turned on and a message is printed to the console. If no motion is detected, the LED is turned off and a different message is printed.The
delayfunction is used to pause the program for 1 second before checking the motion sensor pin again. This creates a loop that continuously checks for motion.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →