Hello! So, recently, I wanted to combine 3 codes. But I have an error with pinMode. If someone helps me, Thank you so much!! This is the code:
/*
Fade
This example shows how to fade an LED on pin 9 using the analogWrite()
function.
The analogWrite() function uses PWM, so if you want to change the pin you're
using, be sure to use another PWM capable pin. On most Arduino, the PWM pins
are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade
*/
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
pinMode = (LED_BUILTIN, OUTPUT);
const int sensorPin = 0;
const int ledPin = 10;
int lightCal;
int lightVal;
void setup{
// We'll set up the LED pin to be an output.
pinMode(ledPin, OUTPUT);
lightCal = analogRead(sensorPin);
pinMode =(LED_BUILTIN, OUTPUT);
pinMode = (led, OUTPUT);
}
void loop{
pr()
blink()
fade()
}
void pr()
{
//Take a reading using analogRead() on sensor pin and store it in lightVal
lightVal = analogRead(sensorPin);
//if lightVal is less than our initial reading (lightCal) minus 50 it is dark and
//turn pin 9 HIGH. The (-50) part of the statement sets the sensitivity. The smaller
//the number the more sensitive the circuit will be to variances in light.
if (lightVal < lightCal - 50)
{
digitalWrite(9, HIGH);
}
//else, it is bright, turn pin 9 LOW
else
{
digitalWrite(9, LOW);
}
}
// the loop function runs over and over again forever
void blink() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
// the loop routine runs over and over again forever
void fade() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
and the error is
Fade:19:1: error: 'pinMode' does not name a type
pinMode = (LED_BUILTIN, OUTPUT);
^~~~~~~
Fade:25:6: error: variable or field 'setup' declared void
void setup{
^~~~~
Fade:27:26: error: expected '}' before ';' token
pinMode(ledPin, OUTPUT);
^
Fade:28:3: error: 'lightCal' does not name a type
lightCal = analogRead(sensorPin);
^~~~~~~~
Fade:29:4: error: 'pinMode' does not name a type
pinMode =(LED_BUILTIN, OUTPUT);
^~~~~~~
Fade:30:5: error: 'pinMode' does not name a type
pinMode = (led, OUTPUT);
^~~~~~~
Fade:32:1: error: expected declaration before '}' token
}
^
exit status 1
'pinMode' does not name a type
any ideea? The error messages are in void setup(). Or so I think