Skip to content

Commit

Permalink
Fixed the selection system
Browse files Browse the repository at this point in the history
  • Loading branch information
Meteoroetem committed Jun 7, 2023
1 parent 1d71210 commit 4299d01
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
27 changes: 18 additions & 9 deletions Finishing-Project.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <legacy.h>
#include <NoiascaLiquidCrystal.h>

#include<Wire.h>
#include<ezButton.h>
#include<LiquidCrystal_I2C.h>
#include<lcd_wire.h>
#include "NeoPixel.h"
#include "Vector2.h"
#ifdef __AVR__
Expand All @@ -13,17 +16,19 @@

ezButton butt(BTN_PIN);
NeoPixel neoPixel(16,4,NEO_GRB + NEO_KHZ800);
LiquidCrystal_I2C lcd(0x28,16,2);
LiquidCrystal_Wire lcd(0x28,16,2);

Vector2 stickPos;

uint32_t colors[] = {neoPixel.Color(239, 71, 111), neoPixel.Color(75, 163, 195), neoPixel.Color(89, 60, 143), neoPixel.Color(249, 219, 189)};

void setup()
{
lcd.print("שלום עולם");
neoPixel.begin();
neoPixel.clear();
for(int pixel = 0; pixel < 16; pixel++){
neoPixel.setPixelColor(pixel, neoPixel.ColorHSV(pixel*5461,255,255-pixel));
neoPixel.setPixelColor(pixel, neoPixel.ColorHSV(pixel*4096,255,255-pixel));
neoPixel.show();
delay(50);
}
Expand All @@ -33,28 +38,32 @@ void setup()
neoPixel.show();
delay(50);
}
neoPixel.setBrightness(30);
Serial.begin(9600);
}

void loop()
{
stickPos.x = analogRead(STCK_X_PIN)-512;
stickPos.y = analogRead(STCK_Y_PIN)-511;

int pixels = (stickPos.GetUnsignedAngle()*180/M_PI)/45;
int uAngle = stickPos.GetUnsignedAngle();
double magnitude = stickPos.GetMagnitude();
int pixels = (uAngle*180/M_PI)/(360/4) - floor((uAngle*180/M_PI)/(360/4))>= 0.5 ? floor((uAngle*180/M_PI)/(360/4)) + 1 : floor((uAngle*180/M_PI)/(360/4));

neoPixel.clear();
if(stickPos.GetMagnitude() >= 5){
neoPixel.setPixelColor(8, pixels, 255, 255, 255);
if(stickPos.GetMagnitude() > 5){
neoPixel.setPixelColor(4, pixels, colors[pixels]);
}
neoPixel.show();

#pragma region Debug Printing
String debugString = "Stick X: " + String(stickPos.x, DEC)
+ " Stick Y: " + String(stickPos.y, DEC) + " Stick Angle: " + String(stickPos.GetSignedAngle()*180/M_PI, DEC)
+ " Stick Unisgned Angle: " + String(stickPos.GetUnsignedAngle()*180/M_PI, DEC)
+ " Pixel: " + String(pixels, DEC);// + "Stick Y: " + stickY;
+ " Stick Unisgned Angle: " + String(uAngle*180/M_PI, DEC) +
" Magnitude: " + String(magnitude, DEC) +
" Pixels: " + String(pixels, DEC);// + "Stick Y: " + stickY;
Serial.println(debugString);
#pragma endregion

}

9 changes: 8 additions & 1 deletion NeoPixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

void NeoPixel::setPixelColor(int segmentCnt, int segmentNum, uint8_t r, uint8_t g, uint8_t b){
int segmentSize = numPixels()/segmentCnt;
for (int pixel = segmentSize * (segmentNum - 1) + 1; pixel <= segmentSize * segmentNum; pixel++)
for (int pixel = segmentSize * segmentNum; pixel < segmentSize * (segmentNum+1); pixel++)
{
Adafruit_NeoPixel::setPixelColor(pixel, r, g, b);
}
}
void NeoPixel::setPixelColor(int segmentCnt, int segmentNum, uint32_t c){
int segmentSize = numPixels()/segmentCnt;
for (int pixel = segmentSize * segmentNum; pixel < segmentSize * (segmentNum+1); pixel++)
{
Adafruit_NeoPixel::setPixelColor(pixel, c);
}
}
1 change: 1 addition & 0 deletions NeoPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ class NeoPixel : public Adafruit_NeoPixel
using Adafruit_NeoPixel::Adafruit_NeoPixel;
using Adafruit_NeoPixel::setPixelColor;
void setPixelColor(int segmentCnt, int n, uint8_t r, uint8_t g, uint8_t b);
void setPixelColor(int segmentCnt, int segmentNum, uint32_t c);
};
4 changes: 2 additions & 2 deletions Vector2.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Vector2{
public:
int x;
int y;
double x;
double y;
double GetMagnitude();
double GetSignedAngle();
double GetUnsignedAngle();
Expand Down

0 comments on commit 4299d01

Please sign in to comment.