I am using raspberry pi 4b along with Freenova kit. I am trying to make the LED blink however it does not blink instead it is ON of the time. I have tried different code (C,Python,Java) but none of it seems to work. What am I doing wrong? below is my Java code that I execute in Processing. None of it works, why? I want Java code the most.
import processing.io.*;
int ledPin = 17;
//define ledPin
boolean ledState = false;
//define ledState
void setup() {
size(100, 100);
frameRate(1);
//set frame rate
GPIO.pinMode(ledPin, GPIO.OUTPUT);
//set the ledPin to output mode
}
void draw() {
ledState = !ledState;
if (ledState) {
GPIO.digitalWrite(ledPin, GPIO.HIGH);
//led on
background(255, 0, 0); //set the fill color of led on
} else {
GPIO.digitalWrite(ledPin, GPIO.LOW);
//led off
background(102); //set the fill color of led off
}
}
Python code:
import RPi.GPIO as GPIO
import time
ledPin = 11 # define ledPin
def setup():
GPIO.setmode(GPIO.BOARD) # use PHYSICAL GPIO Numbering
GPIO.setup(ledPin, GPIO.OUT) # set the ledPin to OUTPUT mode
GPIO.output(ledPin, GPIO.LOW) # make ledPin output LOW level
print ('using pin%d'%ledPin)
def loop():
while True:
GPIO.output(ledPin, GPIO.HIGH) # make ledPin output HIGH level to turn on led
print ('led turned on >>>') # print information on terminal
time.sleep(1) # Wait for 1 second
GPIO.output(ledPin, GPIO.LOW) # make ledPin output LOW level to turn off led
print ('led turned off <<<')
time.sleep(1) # Wait for 1 second
def destroy():
GPIO.cleanup() # Release all GPIO
if __name__ == '__main__': # Program entrance
print ('Program is starting ... \n')
setup()
try:
loop()
except KeyboardInterrupt: # Press ctrl-c to end the program.
destroy()
C code:
#include <wiringPi.h>
#include <stdio.h>
#define ledPin 0 //define the led pin number
void main(void)
{
printf("Program is starting ... \n");
wiringPiSetup(); //Initialize wiringPi.
pinMode(ledPin, OUTPUT);//Set the pin mode
printf("Using pin%d\n",ledPin); //Output information on terminal
while(1){
digitalWrite(ledPin, HIGH); //Make GPIO output HIGH level
printf("led turned on >>>\n"); //Output information on terminal
delay(1000); //Wait for 1 second
digitalWrite(ledPin, LOW); //Make GPIO output LOW level
printf("led turned off <<<\n"); //Output information on terminal
delay(1000); //Wait for 1 second
}
}