Anonymous
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#include "eyes.h"
void setup() {
// put your setup code here, to run once:
pinMode(4,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
pinMode(2,INPUT_PULLUP);
Serial.begin(115200);
Serial.println("Booting");
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
// Clear the buffer
display.clearDisplay();
display.display();
}
unsigned char readkey(void){
unsigned char ret=0;
if (digitalRead(4)==0 ) ret=1; //izquierda
if (digitalRead(3)==0) ret+=2; //arriba
if (digitalRead(2)==0) ret+=4; //abajo
return (ret);
}
int xp=16;
int mood=1;
void loop() {
int n;
static int xd=0;
static int espera=0;
static int step=0;
int x1,x2;
if (espera>0) {
espera--;
delay(1);
} else {
x1= xd+ (xp>16? (16+2*(xp-16)):xp);
x2=64+xd+ (xp<16? (-16+(xp*2)) :xp);
switch (step){
case 0:
display.clearDisplay(); // Clear the display buffer
if (xp<6) {
display.drawBitmap(x1, 8, peyes[mood][2][0], 32, 32, WHITE);
display.drawBitmap(x2, 8, peyes[mood][1][1], 32, 32, WHITE);
} else if (xp<26) {
display.drawBitmap(x1, 8, peyes[mood][0][0], 32, 32, WHITE);
display.drawBitmap(x2, 8, peyes[mood][0][1], 32, 32, WHITE);
} else {
display.drawBitmap(x1, 8, peyes[mood][1][0], 32, 32, WHITE);
display.drawBitmap(x2, 8, peyes[mood][2][1], 32, 32, WHITE);
}
display.display();
espera=random(250, 1000);
n=random(0,7);
if (n==6) {
step=1;
} else {
step=2;
}
break;
case 1:
display.clearDisplay(); // Clear the display buffer
display.drawBitmap(x1, 8, eye0, 32, 32, WHITE);
display.drawBitmap(x2, 8, eye0, 32, 32, WHITE);
display.display();
espera=100;
step=0;
break;
case 2:
n=random(0,10);
if (n<5) xd--;
if (n>5) xd++;
if (xd<-4) xd=-3;
if (xd>4) xd=3;
espera=0;
step=0;
break;
}
}
//n=0;
n=readkey();
if (n==2) xp=(xp<=0?0:xp-1);
if (n==4) xp=(xp>=32?32:xp+1);
if (n==1) {
mood=(mood>=5?0:mood+1);
do {} while (readkey()!=0);
}
if (n!=0) { espera=0; step=0; }
}
Anonymous
#include <stdio.h>
#include <conio.h>
int abhi()
{
int a[10000],i,n,key;
printf("Enter size of the array : ");
scanf("%d", &n);
printf("Enter elements in array : ");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
printf("Enter the key : ");
scanf("%d", &key);
for(i=0; i<n; i++)
{
if(a[i]==key)
{
printf("element found ");
return 0;
}
}
printf("element not found");
}
Владимир
how to include openmp? i istalled lib into /opt/homebrew/opt/libomp and set this dir to compiler settings. but anyway linker throw error:
clang: error: linker command failed with exit code 1
what I'm doing wrong?
c_cpp_properties.json:
"includePath": [
"${workspaceFolder}/**",
"/opt/homebrew/opt/libomp/include/**",
"/opt/homebrew/opt/libomp/lib/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"intelliSenseMode": "macos-clang-arm64",
"browse": {
"path": [
"/opt/homebrew/opt/libomp/include",
"/opt/homebrew/opt/libomp/lib"
]
}
main.cpp:
#include </opt/homebrew/opt/libomp/include/omp.h>