Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#from microbit import *
#include <LiquidCrystal.h>

LiquidCrystal lcd(0, 1, 2, 8, 11, 13);

void setup()
{
  lcd.begin(16,1);
  lcd.print("hello, world!");
}

void loop() {}


I ADDED THE FOLLOWING CODE,BUT I AM GETTING ERROR;

4:15: error: expecting expression near `lcd`
4:15: error: unexpected token near `lcd`
4:18: error: expecting  near `(`


What I have tried:

I tried to change the numbers,or check the connections,please sen the circuit and code
Posted
Updated 19-Nov-21 6:47am

I think you first need to decide whether you're using C++ or python.

Then once you decide, you need to code in one at a time.
 
Share this answer
 
v2
Comments
Rima Farouk 19-Nov-21 14:05pm    
PYTHON
It looks like you're trying to mix python and C in the same source file, and that just won't work. For python, the # char starts a comment that extends to the end of the line so the lines
#from microbit import *
#include <LiquidCrystal.h>
are completely ignored. For C the first of those two lines should produce an error regarding an invalid preprocessing directive #from. In C you can't define and initialize an object outside of a function - i.e. the definition of LiquidCrystal lc(...), but then again in Python, you don't declare functions as void setup(). And in C all programs need to have a main() function where the program starts. So you seem to be confused about what language you are trying to create your program in. For whatever library or framework or whatever is providing you with LiquidCrystal or the microbit python package, take a look at any accompanying documentation, or the providers web site and see if there is any tutorial or examples on how to use the package.
 
Share this answer
 
To add to what honey the codewitch says, you cannot feed C code to a Python interpreter, or feed Python code to a C compiler: that won't work any better than sending a letter in Swahili to a Chinese-only reader.

What you are doing is mixing the two and hoping it will work - it won't. What you will probably need to do is write the code to access the display at a low level in C, then use the compiled version to call from your Python code.
This may help: Python Bindings: Calling C or C++ From Python – Real Python[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900