Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
//importing libraries import cc.arduino.*; import processing.serial.*; import controlP5.*; import ddf.minim.*; //declare library entities Minim minim; AudioSample beep; AudioPlayer player; ControlP5 cp5; Arduino arduino; //creating a struct class public class struct{ boolean R; boolean G; boolean B; boolean all; } //declaring global variables and pins struct correct = new struct(); boolean colorSet = false; boolean timeOver = false; float ValueR, ValueG, ValueB, InR, InG, InB; int pins[] = {0,1,2}; int difficulity; long startTime; PFont font; void setup(){ //setup function (runs only once) size(360,480); //window size background(0); //background color //declare font type and size font = createFont("Times",35); //set up library entities arduino = new Arduino(this, "COM5", 57600); minim = new Minim(this); cp5 = new ControlP5(this); beep = minim.loadSample("beep.mp3", 2048); player = minim.loadFile("moon.mp3", 2048); //set up the pins as Input pins for(int i =0; i<3;i++){ arduino.pinMode(pins[i], arduino.INPUT); } // play the music player.play(); player.loop(); //select the font for the difficulity selection menu cp5.setControlFont(font); //create buttons for the difficulites cp5.addButton("Easy",0,20,20,320,45); cp5.addButton("Normal",1,20,90,320,45); cp5.addButton("Hard",2,20,160,320,45); cp5.addButton("Extreme",3,20,230,320,45); } void controlEvent(ControlEvent theEvent) { //a function that reads event occurance if(theEvent.isController()) { //checks to see if the even is a controller (a button) generate(); //generates the random color difficulity = (int)theEvent.controller().value(); //sets difficulity bhide(); //hides the buttons startTime = millis(); //intializes the start Time } } void generate(){ //genrate a random color using the build in random function ValueR = random(0,255); ValueG = random(0,255); ValueB = random(0,255); colorSet = true; } void bhide(){ //hides all the buttons cp5.controller("Easy").hide(); cp5.controller("Normal").hide(); cp5.controller("Hard").hide(); cp5.controller("Extreme").hide(); } void draw(){ //main function (loops) when the main menu is loaded it wont do anything if(correct.all == true){ // if all the input is correct displays the correct values then a you win message fill(255); text((int)ValueR+" "+(int)ValueG+" "+(int)ValueB, 60 ,70); long currentTime = millis(); if(currentTime-startTime>5000){ background(255); fill(0); text("You Win!",100, 220); } } else if(timeOver == true){ //if the user fails to get the right values he/she will get a game over message background(255); text("Game Over",100, 220); } else if (colorSet == true){ //when the color is set (after a difficulity is selected) //read the values of the potentiometers and map them to the colors range (0-255) float In0 = arduino.analogRead(pins[0]); InR = map(In0, 0, 1023, 0, 255); float In1 = arduino.analogRead(pins[1]); InG = map(In1, 0, 1023, 0, 255); float In2 = arduino.analogRead(pins[2]); InB = map(In2, 0, 1023, 0, 255); color cur = color(InR,InG,InB); //set the current color to a color data type to be used to display it in hex background(255); //draw the background fill(ValueR, ValueG, ValueB); rect(10,10,340,100); //draws the rectangle with color that the user has to guess fill(InR,InG,InB); rect(10,120,340,200); //draws a rectangle with the color thet the user inputs through the potentiometers fill(255); text("#"+hex(cur,6),110,230); //gives the hex value of the user inputed color in hex fill(InR,0,0); rect(10,330,110,100); //draw the red rectanlge for the user input fill(255); text((int)InR,50,390);//Write the value of the user input for red fill(0,InG,0); rect(125,330,110,100);//draw the Green rectanlge for the user input fill(255); text((int)InG,160,390);//Write the value of the user input for green fill(0,0,InB); rect(240,330,110,100);//draw the blue rectanlge for the user input fill(255); text((int)InB,280,390);//Write the value of the user input for blue fill(0); switch(difficulity){ //a switch statement to switch between each difficulity case(0): text("Easy",145,470); //displays easy instead of timer because the easy mode has no time limit check(20); //checks the values with a tolarence of 40 (20 higher and 20 less than the right value) break; case(1): text(counter(90),165,470);//displays a countdown from 90 check(15); //checks the values with tolarence of 30 break; case(2): text(counter(60),165,470); check(10); break; case(3): text(counter(30),165,470); check(5); break; } } } void check(int n){ //compares the input values with the random value if(abs(ValueR-InR) <= n){//if the values are in range sets the color to correctness to true and plays a tone if(correct.R == false){ correct.R = true; beep.trigger(); } } else{ //otherwise the color is not correct correct.R = false; } if(abs(ValueG-InG) <= n){ if(correct.G == false){ correct.G = true; beep.trigger(); } } else{ correct.G = false; } if(abs(ValueB-InB) <= n){ if(correct.B == false){ correct.B = true; beep.trigger(); } } else{ correct.B = false; } if(correct.R == true && correct.G == true && correct.B == true){//when all the colors are correct set the value of all to true and reset the timer correct.all = true; startTime = millis(); } } int counter(int secs){ //a timer function long counter; long currentTime = millis(); secs = secs * 1000; counter = (startTime+secs) - currentTime; if(counter < 0){ timeOver = true; return 0; } else{return (int)counter/1000;} } void stop() //terminates the sound when the processing app is closed while pressing a key { //used to prevent the problem of having the sound on after the app exits minim.stop(); super.stop(); }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
Python | 1 hour ago | 0.13 KB
Decentralized Moneys
1 hour ago | 0.42 KB
120 million in 5 years
3 hours ago | 0.12 KB
December smells like money
3 hours ago | 0.07 KB
Crypto Liquidity Pools
3 hours ago | 0.47 KB
Trustless Finance
3 hours ago | 0.51 KB
The Lunar Kitsune - Yohana Tsukiko
4 hours ago | 21.38 KB
Crypto profits are insane
4 hours ago | 0.12 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!